Created
July 13, 2018 17:39
-
-
Save JakeTheCorn/1002e6b59d04bd554ac2ab689369c22c to your computer and use it in GitHub Desktop.
Post Json 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 createFriend() { | |
requestURL := "http://rest.learncode.academy/api/johnbob/friends" | |
payload := strings.NewReader("{\"FirstName\": \"Billy\"}") | |
req, _ := http.NewRequest("POST", requestURL, payload) | |
req.Header.Add("content-type", "application/json") | |
res, err := http.DefaultClient.Do(req) | |
if err != nil { | |
panic(err) | |
} | |
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