Documentation
¶
Overview ¶
Package adapters-chi demonstrates the three-layer codec pipeline pattern using the chi router. The architecture mirrors adapters-nethttp exactly — the only difference is the HTTP router and how path variables are extracted.
Three boundary codecs:
Codec[CreateUserReq] — HTTP request contract (what the client sends) Codec[UserRecord] — database contract (the SQL model) Codec[User] — HTTP response contract (what the client receives)
Two pure domain functions connect them (Layer 2):
buildUserRecord(CreateUserReq) UserRecord — request → DB record buildUserResponse(UserRecord) User — DB record → response
Routes:
- POST /users — body validate, response headers + cookies (codec-validated), content negotiation
- GET /users/{id} — UUID path param, BuildPath type-safe URL construction
- GET /users — query params (page, search)
- GET /profile — request-side cookie + header validation
A CountingObserver wired into every route collects per-request metrics and per-field validation errors without any metrics library dependency.
Run with: go run ./examples/adapters-chi