Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ping JSON API in Golang
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://community-hacker-news-v1.p.rapidapi.com/item/8863.json?print=pretty"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-rapidapi-host", "community-hacker-news-v1.p.rapidapi.com")
req.Header.Add("x-rapidapi-key", "472e13f6d7msh84492a2444096d4p1edbffjsn3ff4c1075778")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.