Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing HackerNews API

I'm trying to access the HackerNews API to practice Go.

Anytime I go to my localhost to try see an output from Firebase database (where the data is stored) I am met with a Google Accounts authentication form.

Any help on this would be appreciated. In my terminal I used curl to check if I was getting a response from the server. I got a 200 OK response with content.

I thought I might be missing a Firebase client library but I'm not sure if that is the issue right now.

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    response, err := http.Get("https://hacker-news.firebaseio.com/v0/item/8863.json")
    if err != nil {
        fmt.Printf("The http request failed with the error %s\n", err)
    } else {
        data, _ := ioutil.ReadAll(response.Body)
        fmt.Fprintf(w, string(data))
    }
}
func main() {
    fmt.Println("Starting the applicaiton")
    http.HandleFunc("/", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))

}
like image 404
mangokitty Avatar asked Mar 23 '26 06:03

mangokitty


1 Answers

Aren't you suppose to add .json to URL (via https://github.com/HackerNews/API)?

e.g https://hacker-news.firebaseio.com/v0/item/8863.json

like image 107
Oleg Butuzov Avatar answered Mar 26 '26 10:03

Oleg Butuzov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!