Skip to content

Instantly share code, notes, and snippets.

@JakeTheCorn
Created July 14, 2018 03:17
Show Gist options
  • Save JakeTheCorn/967efdec8245e14f751cb432ae24eefe to your computer and use it in GitHub Desktop.
Save JakeTheCorn/967efdec8245e14f751cb432ae24eefe to your computer and use it in GitHub Desktop.
Put Example in Golang
func putFriend() {
resourceURL := "http://rest.learncode.academy/api/johnbob/friends/5b496ac679f71d000f953faa"
payload := strings.NewReader("{\"FirstName\": \"Bob\"}")
req, err := http.NewRequest("PUT", resourceURL, payload)
if err != nil {
panic(err)
}
req.Header.Add("content-type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
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