- Easy to write and read
- JSON mode enabled by default
- Sets
Content-Type
to beapplication/json
- uses
json.NewDecoder(w).Encode(data)
- Sets
- Simplifies status code responses
type User struct {
ID string `json:"id"`
Name string `json:"name"`
}
func CreateUserHandler(w http.ResponseWriter, r *http.Request) {
u := &User{ID: "123", Name: "Felix"}
reply.Created(w, u)
}