Created
July 14, 2018 03:17
-
-
Save JakeTheCorn/967efdec8245e14f751cb432ae24eefe to your computer and use it in GitHub Desktop.
Put Example 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
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