HTTP
Results
Return status, headers, and body values from HTTP handlers.
http.Result represents the response produced by a handler.
type Result interface {
// StatusCode returns the HTTP status code.
StatusCode() Status
// BodyValue returns the value that should be written as the response body.
BodyValue() any
// Header returns response headers.
Header() Header
}Use http.TypedResult[T] for structured responses.
return http.TypedResult[UserDTO]{
Body: user,
Status: http.StatusOK,
Headers: http.Header{
"Cache-Control": {"no-store"},
},
}, nilIf Status is not set, TypedResult defaults to StatusOK.
Empty responses
For handlers that do not need a serialized body, write status through the response and return no result.
func (c *HealthController) health(ctx *http.Context) error {
ctx.Response().SetStatus(http.StatusNoContent)
return nil
}Use results when the framework should write a structured response. Use direct response access when the handler owns the raw response behavior.
