Created
January 13, 2020 21:32
-
-
Save topherPedersen/10eb7d62bf8e9466d1de273aea79d45d to your computer and use it in GitHub Desktop.
Ping JSON API in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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