4 ms·
Only using the official API is quite cumbersome, as fetching a story with comments requires one network request per each comment. Instead, try considering the
by goranmoomin 4y ago
Only using the official API is quite cumbersome, as fetching a story with comments requires one network request per each comment.
Instead, try considering the (more unknown) Algolia API[0]. It supports fetching the entire tree in one request. Unfortunately the comments aren’t sorted, so you’ll still have to use the official one (or parse the HN HTML) if you need that.
For my HN client[1], I parse the HN HTML (as it’s required for voting), and sort the comments from the Algolia API. It’s much faster than recursively requesting the official API.
[0]: https://hn.algolia.com/api https://hn.algolia.com/api
[1]: https://github.com/goranmoomin/HackerNews https://github.com/goranmoomin/HackerNews
- CodesInChaos 4y agoIf you already parse the html, what's the point in calling the Algolia API at all?
- rajnathani 4y agoI believe HN's website has a rate-limiter even for viewing, which the HN API doesn't have.
- adamredwoods 4y agoI found this interesting, looking at the Firebase API. I guess one could get the min/max item ids for the child posts, and query the range of ids (startAt(), endAt()). Van Puffelen answers some of this here, but he doesn't get into specific queries: https://www.youtube.com/watch?v=66lDSYtyils https://www.youtube.com/watch?v=66lDSYtyils He also mentions here that Firestore offers a bit more for WHERE type clauses over Firebase: https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase/26701282#26701282 https://stackoverflow.com/questions/26700924/query-based-on-...
- catnip09 4y agoYeah, I built a graphql API for HN for this reason. It will let you fetch all comments, users, and posts in a single request. https://hngraphql.fly.dev/graphql https://hngraphql.fly.dev/graphql