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!

We love Reddit at Pusher. You don’t have to take our word for it though, with over 731 million unique visitors last year, and over 40 million story submissions, it’s a pretty big deal however you look at it. It’s a weird and wonderful place, whether you want to keep up to speed with programming and JavaScript, or simply just want to see beautiful photos of planet Earth, Reddit has it all (and then some).

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.

The solution? Building a realtime Reddit API that allows you to subscribe to a subreddit (content on a particular topic, like JavaScript) and receive every single public story posted within it. This is what we’ve built, open and free for everyone.

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).

And more…

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-listing event (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.

Here’s an example that subscribes to the “/r/AskReddit” subreddit using JavaScript and outputs each new story to the browser console:

<!-- Include the Pusher JavaScript library -->
<script src="http://js.pusher.com/2.2/pusher.min.js"></script>

  // Open a Pusher connection to the Realtime Reddit API
  var pusher = new Pusher("50ed18dd967b455393ed");

  // Subscribe to the /r/AskReddit subreddit (lowercase)
  var subredditChannel = pusher.subscribe("askreddit");

  // Listen for new stories
  subredditChannel.bind("new-listing", function(listing) {
    // Output listing to the browser console

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).

Pusher Reddit Realtime API Demo

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!

  • Wesley

    *Love* the idea, but the demo is not working for me. It’s been ‘listening’ (all 4) for well over a minute now.

    • Wes

      I’m an idiot, and I should be ashamed. It’s still early, apologies :<.

      • No problem, it happens to all of us. Let me know if you have any other questions.

  • WhyDoesThisNotWorkWell

    I’ve been trying to use the API (and tried the demo) with the subreddits:

    I’ve given the demo app 10+ minutes and I’ve tried to subscribe to these and get the listings on my own as well with no success. Am I confused about which subreddits would be available (these are “public” as far as I know, and your demo autofills for them) or is this just poorly hacked together by a developer advocate?

    • Were submissions posted to those subreddits while you were listening? The API and demo currently doesn’t backdate submissions. If there are no listings appearing for a subreddit then that subreddit is likely not available via the public Reddit API (which is what we hook into). We’ve been testing this app for a week and, although not perfect, it’s stable and has been working great for the subreddits we’ve tested on.

      Let me know if you have any other questions.

  • ncerminara

    Hopefully you guys are still around. I’m using Pusher for a work related project and am loving it. You guys are awesome. I was thinking about writing a tutorial on it for my blog at scotch.io.

    Anyways, with this, is it only realtime, or is there a way to pull from the API say the last 500 posts before the realtime stuff kicks in with Pusher? Or, is there a “History” API. So I could get realtime results from say 2 years ago? I’ve seen stuff like that with third-parties who provide access to the Twitter Firehose. Hoping there’s something like this with Pusher and this reddit API.

    Generally just looking for some additional docs besides the reddit example. Thanks!

    Edit: Also, what other public APIs do you have? Is there a list somewhere?

    • We’re still around! That’s awesome that you’re using us for a project, I’m glad you’re happy with us. Let me know if you do write a tutorial, I’d love to see it.

      As things stand, you can only consume Reddit posts in realtime. It’s possible in the future to add a historic log though it’s not something we’ve looked at yet as we didn’t want to overcomplicate the first version of the API. Everything the current API offers is documented on the GitHub repo.

      The other public API we’ve released is for Product Hunt, you can find out about it here: http://pusher.com/tutorials/product-hunt

  • Nico

    Hi there, nice API, but where’s the methods documentation? I’m kinda lost, can I use it to keep track of a single thread? See how people vote it and stuff? Thanks ;)

  • Fred

    I’m interested in building something with this API, but I’m not receiving any events when I listen on a channel like “askreddit”. I’m also not seeing new listings on the demo linked here. Is the Reddit API still functional?

  • Hmm is anyone else encountering problems with the pictures
    on this blog loading? I’m trying to figure out
    if its a problem on my end or if it’s the blog. Any responses would
    be greatly appreciated.

    web site, Patrick,

  • Jason, I don’t read him the way you do. Yes he talks about slavery and pickin cotton AND he more or less is asking which life was better? I believe that I would chose pickin cotton to what I have seen in the black community where I lived for 40 years. I would suggest we go talk to the blacks that know Cliven and see what they tell you.

  • I thought they fought to defend The Constitution. All this talk about fighting for the flag is an appeal to emotion instead of reason and law. Such demagoguery, and that’s what it is, can be dangerous.

  • We prefer to honor several other world wide web web sites on the net, even if they aren

  • Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is valuable and all. Nevertheless think of
    if you added some great photos or videos to give
    your posts more, “pop”! Your content is excellent but with images and clips, this site
    could definitely be one of the greatest in its niche.
    Awesome blog!

    Here is my webpage large outdoor fountains for sale

  • gucci shoes jingle
    real giuseppe zanotti http://www.euroart.co.uk/

  • I really like reading a post that can make people think.
    Also, thanks for allowing for me to comment!

    Also visit my blog post: pure garcinia

  • hello there and thank you for your information – I have
    certainly picked up something new from right here.
    I did however expertise several technical points using this website, as I experienced to reload the web
    site many times previous to I could get it to load correctly.

    I had been wondering if your web host is OK? Not that I’m complaining, but slow loading
    instances times will often affect your placement in google and could damage your quality score if advertising and marketing with Adwords.
    Anyway I’m adding this RSS to my email and could look out for much more of
    your respective exciting content. Ensure that you update this again soon.

About Robin Hawkes

Robin thrives on solving problems through code. He's a Digital Tinkerer, Head of Developer Relations at Pusher, former Technical Evangelist at Mozilla and book author. In his spare time he experiments with new technology and data visualisation, often at the same time.