javafirebasegethacker-news-api

Do I need to use Firebase to access all Hacker News articles?


I have my Java server setup with all the appropriate packages (API, DAO, model, service, etc.). On the Hacker News (HN) website they explain that I should use Firebase to call their API.

Do I need to configure Firebase to access all the HN articles from the API, even though I have access to Java's built-in API call functionalities?

I can retrieve one article and see the JSON data in Postman:

URL getUrl = new URL("https://hacker-news.firebaseio.com/v0/item/29042728.json?print=pretty");
print = pretty
HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();

// If a connection (200 OK) is made, data is buffered
BufferedReader art = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
StringBuffer jsonResponseData = new StringBuffer();
String readLine = null;

// Appends data from the response line by line
while ((readLine = art.readLine()) != null) {
    jsonResponseData.append(readLine);
}

in.close();

Is Firebase still needed for something else?

Reference: Hacker News API


Solution

  • You don't have to use the Firebase SDK to interact with the API, although you can if you want to. Using the Firebase SDK gets you minor performance gains, at the cost of some more implementation complexity. But you can also just make requests to the API endpoints using a normal HTTP client using the API endpoints listed in the documentation (like https://hacker-news.firebaseio.com/v0/item/8863.json).