HTTPHandlers
Handle Functions
Choose between direct response handlers and structured result handlers.
Use http.Handle when the handler writes to the response itself or only needs to
perform side effects.
func (c *HealthController) ConfigureEndpoints(endpoints http.Endpoints) {
endpoints.MapGet("/health", http.Handle(c.health))
}
func (c *HealthController) health(ctx *http.Context) error {
ctx.Response().SetStatus(http.StatusNoContent)
return nil
}Use http.HandleResult when the handler should return a structured response.
func (c *UserController) ConfigureEndpoints(endpoints http.Endpoints) {
endpoints.MapGet("/users/{id}", http.HandleResult(c.getUser))
}
func (c *UserController) getUser(ctx *http.Context) (http.Result, error) {
user, err := c.service.Find(ctx, ctx.Request().PathValue("id"))
if err != nil {
return nil, err
}
return http.TypedResult[UserDTO]{
Body: user,
}, nil
}Use direct response access for low-level response control. Use result handlers when the response is a normal serialized value.
