DEV Community

pilcrowOnPaper
pilcrowOnPaper

Posted on

1

Reddit API is such a mess

I really hate both reddit.com and its mobile app, and was looking for an alternative. I just wanted something minimalistic and lightweight. Apollo, Slide, Narwhal, Comment, BaconReader, photon-reddit... I tried everything I could find and none of them felt nice to use. So, I thought I could make own, how hard can that be? Fetch some data from the API and display it.

Oh, how wrong I was.

First of all, the documentation, uh, leaves a lot to be desired. There's no response body example so I had to call each of them before using them. Some parameters are just left unacknowledged.

My biggest complaint is that there's no easy way to tell if the post is a text, image, GIF, video, embedded video, or embedded image.

is_self means it's a text. is_video means it's a video, but not, since you also have to check post_hint === 'rich:video' and domain === 'v.redd.it'. But even if you know what kind of media it is, getting the media URL is in its self is a hurdle. Sometimes you have check media_embed, maybe media_metadata, or preview.images[0]. Oh, and media.reddit_video.

And the inconsistency.

Sometimes nsfw items are marked as over_18 and other times as over18. Some key-values are missing depending on which endpoint you call, like description from users missing when you search users by a query. Icon URLs are included in either community_icon or icon_img.

And finally, getting the next batch of items.

Reddit API only gives you a max 100 or so items for each API call. If you want to get the next batch of posts, you have you use the after id provided by the previous call. Fine, it works. But, how do you get the next batch of comments in a comment section? Well, the API returns you all the comment ID of comments that weren't included in the first batch. You can get the content of each comment using their ids, but replies to those comments are missing. There's an endpoint that gives you the comment with the replies, but it's missing crucial information like who made them. And don't forget that the object that includes that list of comment ids are inside an array of totally different comment-objects.

There are API wrappers like Snoowrap but I am not willing to see any more response body from reddit.com.

So, my solution?

Create an API wrapper that does all the work for you and returns a clean response body without the fat. Still very much in progress though: https://github.com/pilcrowOnPaper/corsica.

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay