
Why I Stopped Using the Hacker News API Directly (and What I Use Instead)
I've been pulling data from Hacker News for over a year. I started where everyone starts: the official Firebase API. And for about two weeks, it was fine. Then reality set in. The problem with the HN API The Hacker News API is technically correct. It returns items by ID. It returns top story IDs. It does what it says. But if you want to do anything practical — like get the top 50 stories with their comment counts, scores, and metadata in a single call — you're looking at 51 HTTP requests minimum . One for the top stories list, then one per story. Here's what that looks like in Python: import requests def get_top_stories ( n = 50 ): top_ids = requests . get ( ' https://hacker-news.firebaseio.com/v0/topstories.json ' ). json ()[: n ] stories = [] for story_id in top_ids : item = requests . get ( f ' https://hacker-news.firebaseio.com/v0/item/ { story_id } .json ' ). json () stories . append ( item ) return stories This works. It's also painfully slow. On a good day, you're waiting 8-12 s
Continue reading on Dev.to Tutorial
Opens in a new tab



