The handler signature
Every Mizu handler has the same signature:
This signature is Mizu’s
Handler type:
Writing handlers
Basic handler
- Receives the context
cwith request info - Returns
c.Text(200, "...")which sends a response - The
errorreturn isnil(success) becausec.Textreturnsnilon success
Inline handlers
For simple routes, define handlers inline:Reading request data
Use context methods to read from the request:Processing JSON input
Returning errors
Handlers can return errors to indicate failures:- Mizu calls your
ErrorHandlerif you set one - Otherwise, it logs the error and returns 500
Response methods
Handlers send responses using context methods:Handler patterns
Early returns for validation
Separating concerns
Keep handlers thin by extracting business logic:Handler factories
Create handlers that share configuration:Summary
Next steps
Context
Deeper dive into request/response context.
Response
All the ways to send responses.