binding

command
v0.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: MIT Imports: 6 Imported by: 0

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"}'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL