Valentin Gomez

Generation

generate functionTue, 03 Jan 2023

post an api rest and get its value

package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" ) type User struct { Id int `json:"id"` Name string `json:"name"` } func main() { url := "https://jsonplaceholder.typicode.com/users/1" resp, _ := http.Get(url) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) var user User json.Unmarshal(body, &user) fmt.Println(user) }

Questions about programming?Chat with your personal AI assistant