TypeScript client for the Reddit API.
If you are looking for an npm package for accessing the reddit api. The Offical Reddit Client may be the one you are looking for https://github.com/reddit/node-api-client
The purpose of this repo is to create a Reddit Client with TypeScript. I'm on a TypeScript learning journey so I reckon this is a great way to learn.
If you are also interested in learning TypeScript feel free to contribute.
Read the Contributing Guide to get started. Then pick an endpoint from the Reddit API docs and create a pull request.
Just be sure to add unit and e2e tests 🙏🏼
- Include most the official Reddit api endpoints
- Promise-based
- Fully typed. Both for query parameters and responses.
Endpoints Completed so far:
Mostly the 'listing section' https://www.reddit.com/dev/api/#section_listings
- /api/v1/access_token
- /new/
- /r/subreddit/new/
- /hot/
- /r/subreddit/hot/
- /rising/
- /r/subreddit/rising/
- /hot/
- /r/subreddit/hot/
- /r/best/
- /r/subreddit/best/
- /r/subreddit/random/
- /r/subreddit/comments/postId
- /duplicates/postId
Where subreddit is the name of the subredit
npm i reddit-client-apiimportRedditClientfrom"reddit-client-api";constconfig={apiKey: `${process.env.REDDIT_APIKEY}`,apiSecret: `${process.env.REDDIT_APISECRET}`,userAgent: `${process.env.USERAGENT}`,};constmyRedditClient=newRedditClient(config);awaitmyRedditClient.auth({username: `${process.env.USERNAME}`,password: `${process.env.PASSWORD}`});// get Rising Posts limited to 2 posts per page and 2 pagesconstrisingPosts=awaitmyRedditClient.getRisingPosts(2,2);// get Rising Posts by Subreddit sideprojectconstrisingSideprojectPosts=awaitmyRedditClient.getRisingPostsBySubreddit('sideproject',2,2);// get New Posts limited to 2 posts per page and 2 pagesconstnewPosts=awaitmyRedditClient.getNewPosts(2,2);// get New Posts by Subreddit sideprojectconstnewSideprojectPosts=awaitmyRedditClient.getNewPostsBySubreddit('sideproject',2,2);// get Hot Posts limited to 2 posts per page and 2 pagesconsthotPosts=awaitmyRedditClient.getHotPosts(2,2);// get Hot Posts by Subreddit sideprojectconsthotSideprojectPosts=awaitmyRedditClient.getHotPostsBySubreddit('sideproject',2,2);// get Hot Posts limited to 2 posts per page and 2 pagesconstbestPosts=awaitmyRedditClient.getBestPosts(2,2);// get Hot Posts by Subreddit sideprojectconstbestSideprojectPosts=awaitmyRedditClient.getBestBySubreddit('sideproject',2,2);// get duplicate postsconstduplicateListingForPost=awaitmyRedditClient.getPostDuplicate(postID);// get randomconstrandomPost=awaitmyRedditClient.getRandom();This project is licensed under the MIT License
Reach out on https://thefullstack.network/u/jamie Open an issue on GitHub
The goal of this repo is to learn TypeScript so please feel free to contribute. Pull requests are always welcome, and I'll do my best to do reviews as fast as I can.
In the case of a bug report, bugfix or a suggestions, please feel very free to open an issue too.
Please refer to the contribution guide to see how to get started.