Pusher is the perfect platform for turning a static, REST-based API like Reddit’s into a smooth, realtime API utilising the power of WebSockets. The best bit? You don’t need to change anything with an existing REST API to do this!
While Reddit is great, it’s a static experience in which you have to refresh the website to see new stories — you can’t sit back and let them come to you as they happen.
Use-cases for the Pusher Realtime Reddit API
While a realtime Reddit API sounds amazing, what can you actually make with one and why is it useful?
Streaming feed of new stories as they’re posted
The simplest and most obvious thing to do is to provide a realtime feed of stories in some sort of Web app, allowing you to sit back and consume Reddit as it happens. Sort of like Twitter for Reddit.
Email alerts when keywords appear in stories
For a little more productivity, you could automatically monitor the realtime feed of story submissions and monitor it for particular keywords (eg. your business or product). By then using something like SendGrid to send an email alert you can have an immediate awareness and response on Reddit as events occur of interest you.
Posting relevant stories to a chatroom (like Slack and Hipchat)
Like the email alert example, you could also use the realtime feed to monitor keywords and have stories automatically published to wherever you and your team would prefer the information to be displayed (like a Hipchat or Slack chatroom).
There are plenty of other uses for an API like this that haven’t even been dreamed up yet. With such a wealth of data at your fingertips it’s nearly impossible not to find some way to use it productively.
API request and response format
The Pusher Realtime API follows a basic structure. Here is an overview:
- The Pusher application key for the realtime Reddit API is
50ed18dd967b455393ed(you’ll need this to connect to it)
- Each subreddit publishes to a Pusher channel using the name of the subreddit in lowercase and without the “/r/” prefix (eg. “askreddit”)
- New stories are published using the
new-listingevent (how to subscribe)
- Stories are formatted using the standard Reddit API JSON structure
That’s it. We’ve tried to keep things as close to the Reddit REST API as possible.
Using the API
The Pusher Realtime Reddit API has been built with simplicity in mind. All you need to do is subscribe to any subreddit using one of Pusher’s free platform libraries and decide what you want to do with each story.
You can see a working, interactive code example of this on JSBin. It’s not a huge step to take things from here and start visualising new stories in some way.
Try the demo and build your own realtime Reddit app
We’ve built a simple demo that lets you subscribe to realtime updates from any public subreddit (viewer discretion is strongly advised).
Give it a go and see how it inspires you to create your own application using the Pusher Realtime Reddit API. If you’re looking to dive into the good stuff, you can find the Github repo here.
Thinking of making something with this free, no-limits API? Let us know when you have, we’d love to see it!