Exemple #1
0
func handler(w http.ResponseWriter, r *http.Request) {

	fmt.Printf("this is r.Body: %+v \n", r.Body)

	var person Person

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		panic(err)
	}

	if err := json.Unmarshal(body, &person); err != nil {
		panic(err)
	}

	fmt.Println("this is person:", person)

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriterHeader(http.StatusOK)
	if err := json.NewEncoder(w).Encode(person); err != nil {
		panic(err)
	}

}