The Hacker News API documentation says:
If you can use one of the many Firebase client libraries, you really should. The libraries handle networking efficiently and can raise events when things change. Be sure to check them out.
It doesn't specify how to do that though. How can I use the Firebase client libraries to interact with the Hacker News API, to gain more efficient networking and support for listening for events?
You can interact it with it using the Realtime Database API. Set the databaseURL
to https://hacker-news.firebaseio.com
, and you can make queries using the Firebase client libraries. The paths are the same as the paths in the API, without the .json
file extension. For example, this would get data for the user jl
using the web client:
var config = {
databaseURL: "https://hacker-news.firebaseio.com",
};
firebase.initializeApp(config);
var database = firebase.database();
console.log((await database.ref("v0/user/jl").get()).val());