Building with Hono
Time to assemble the pieces. A clean implementation separates routing, validation, and business logic, and wires cross-cutting concerns (auth, errors, CORS) as middleware.
A sensible structure
Section titled “A sensible structure”src/ index.ts // create the app, mount middleware + routes, start the server middleware/ // auth, error handler, CORS, rate limiting routes/ // one module per resource (articles, users, ...) services/ // business logic, independent of HTTP schemas/ // request/response validation (e.g. zod)Handlers stay thin: validate input, call a service, shape the response. Services know nothing about HTTP, so they are easy to unit-test.
A small resource, end to end
Section titled “A small resource, end to end”This Hono app brings together validation, a consistent error shape, and proper status codes for an articles resource. Open it in StackBlitz to run it:
Notice how every idea from the course shows up: a paginated collection envelope, 201 Created with Location, 422 validation with field errors, 404 via a thrown typed error, and one central onError producing problem+json.