Documentation
¶
Overview ¶
Example: request binding + validation, two ways.
Both endpoints accept the same JSON payload and produce the same shape of 200 / 400 response. The difference is mechanical, not behavioural:
POST /users — uses server.JSONHandler. One function, business
logic only. Bind, validate, render are wrapped.
POST /users-manual — uses the lower-level server.BindJSON and renders
the 400 envelope by hand. Useful when you need
to add headers, stream, or build a custom shape.
Try it:
go run ./examples/binding &
curl -s -X POST localhost:8080/users \
-H 'Content-Type: application/json' \
-d '{"name":"Ada","email":"ada@example.com","age":36,"role":"admin"}'
curl -s -X POST localhost:8080/users \
-H 'Content-Type: application/json' \
-d '{"name":"A","email":"nope","age":12,"role":"superuser"}'
Click to show internal directories.
Click to hide internal directories.