seanmturley / natureddit

A simple Reddit client, featuring a landing page dedicated to nature with posts pulled from a curated list of subreddits.
0 stars 1 forks source link

Add single post API call #79

Closed seanmturley closed 1 year ago

seanmturley commented 1 year ago

Description

Implement the API endpoint and corresponding loader function.

Implementation details

The API call needs to be made to www.reddit.com/r/[subreddit]/comments/[postID]/[abbreviated_post_title].json

The entire path is available in the permalink property of a post as pulled from e.g. the subreddit API endpoint, and it's sufficient to simply add ".json" to the end (the trailing "/" before the ".json" doesn't affect the response).

seanmturley commented 1 year ago

Implemented postLoader function, and abstracted the common API request code from the two loader functions into a new makeApiRequest function.

Added the getPost endpoint to the redditApi, with a simple transformation of the response to surface post and comment data.

Added accessing of the response data to the Post component.