How to limit the number of stories returned by the Hacker News API

Playing around with the Hacker News API and noticed that it’s returning hundreds of story IDs when queried. It’s not ideal and can take longer to resolve. Since the Hacker News API is handled by Firebase we can use the limitToFirst or limitToLast query params to only return a set number of the first or last stories.

Here’s what the top stories query would look like to return the first 10:

https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty&limitToFirst=10&orderBy="$key"

Which would return something like:

[
  23546706,
  23543131,
  23543277,
  23543043,
  23526516,
  23546206,
  23540704,
  23547367,
  23538015,
  23537261
]

Link to more info: Firebase