Hacker News now has an API. It's Firebase

Today Y Combinator is launching an API for it’s popular startup-focused news aggregator, Hacker News. As a YC company that launched on HN ourselves, we’re thrilled that they are putting their public data into Firebase. This means that developers can easily get realtime access to HN’s data
through the standard Firebase Web, iOS, Android and REST APIs.

With 2.6 million unique visitors per month, Hacker News (HN) has a huge audience of programmers and entrepreneurs. HN users submit interesting stories from around the web that are upvoted by other users. When a post receives enough upvotes it makes it to the front page. This results in a lot of interesting content and discussion, and a rapidly changing set of articles. HN is so popular that developers have taken to scraping the site in order to access its content. Using Firebase now makes it much easier for developers to build apps using data from HN.

Firebase is an ideal way to distribute HN in realtime across a variety of clients. With our scalable, easy to use platform HN now has a realtime API available to Web, iOS, and Android developers. The API is also accessible on other platforms through our REST API.

To quote Kevin Hale from YC:

In addition to giving developers near real-time access to our data, we got out of the box well designed, easy to use SDKs for iOS, Android and the Web, in addition to a REST API for developers building server apps. It should hopefully making switching your apps fairly painless.

Get started

You can access the HN API today, here’s a simple example that displays the top rated HN article and updates in realtime.

See this example running live on JSFiddle.

var ref = new Firebase("https://hacker-news.firebaseio.com/v0/");
var itemRef;

ref.child('topstories').child(0).on('value', function(snapshot) {
 if(itemRef) {
  itemRef.off();
 }

 //Get the ID of the top article
 var id = snapshot.val();

 //Get the article details and update in realtime
 itemRef = ref.child('item').child(id);
 itemRef.on('value', function(snapshot) {   
  var item = snapshot.val();

  document.getElementById("score").innerHTML = item.score;

  var anchor = document.getElementById("article_a")
  anchor.innerHTML = item.title;
  anchor.href = item.url;

  document.getElementById("comments_a").href = "https://news.ycombinator.com/item?id=" + item.id;
 });  
});
Firebase *ref = [[Firebase alloc] initWithUrl:@"https://hacker-news.firebaseio.com/v0/"];
__block Firebase *itemRef = nil;
Firebase *topStories = [ref childByAppendingPath:@"topstories"];
Firebase *firstStory = [topStories childByAppendingPath:@"0"];

FirebaseHandle handle = [firstStory observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    if(itemRef != nil) {
        [itemRef removeObserverWithHandle: handle];
    }
    
    NSString *itemId = [NSString stringWithFormat:@"item/%@",snapshot.value];
    itemRef = [ref childByAppendingPath:itemId];

    [itemRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *itemSnap) {
        NSLog(@"%@", itemSnap.value);
    }];     
}];
final Firebase ref = new Firebase("https://hacker-news.firebaseio.com/v0/");
final Map<Long, ValueEventListener> valueEventListenerMap = new HashMap();

ref.child("topstories").child("0").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
        if(!valueEventListenerMap.isEmpty()) {
            for(Long id : valueEventListenerMap.keySet()) {
                ref.child("item").child(String.valueOf(id)).removeEventListener(valueEventListenerMap.get(id));
            }

            valueEventListenerMap.clear();
        }


        //Get the ID of the top article
        Long id = (Long) snapshot.getValue();

        //Get the article details and update in realtime
        ValueEventListener articleListener = ref.child("item").child(String.valueOf(id)).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                Map itemMap = (Map) snapshot.getValue();

                // Print the title to the console
                System.out.println(itemMap.get("title"));
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

        valueEventListenerMap.put(id, articleListener);
    }

    @Override
    public void onCancelled(FirebaseError firebaseError) {

    }
});  

Check out the full HN documentation at hacker-news.firebaseapp.com.

Firebase is your API

With more than 100,000 developers using our platform, we’ve seen Firebase used both as the entire backend for apps as well as to power specific realtime features in apps. A growing use case has been loading data into Firebase to expose an API to other developers. Traditionally, building and maintaining a public API is a big undertaking; often entire teams are dedicated to it. It’s not easy to give third party developers access to your data in a way that’s both safe for your users and powerful for those developers. With Firebase, all you need to do is sync data to your Firebase and API consumers can then use one of Firebase’s realtime clients or the REST API to consume that data. You don’t have to worry about scaling with developer usage and or documenting anything beyond your data structure.

We can’t wait to see what you build!