Skip to content

Instantly share code, notes, and snippets.

@JakeTheCorn
Created July 13, 2018 17:39
Show Gist options
  • Save JakeTheCorn/21dcdd04381298e0265d9f50b100c9a1 to your computer and use it in GitHub Desktop.
Save JakeTheCorn/21dcdd04381298e0265d9f50b100c9a1 to your computer and use it in GitHub Desktop.
How to fetch JSON in Go
func getFriends() {
resp, err := http.Get("http://rest.learncode.academy/api/johnbob/friends")
if err != nil {
panic(err)
}
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
stringBody := string(bytes)
fmt.Println(stringBody)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment