Controllers
Controllers handle incoming requests. Learn how to create REST and WebSocket controllers, set path prefixes, and bind middleware, guards, and interceptors.
Controllers
A Controller is responsible for receiving requests and returning responses. REST controllers embed common.REST; WebSocket controllers embed common.WS.
Creating a REST Controller
Every controller must implement the NewController() common.Controller method. This is where you set the path prefix and bind pipeline layers.
Handler Methods
Method names are parsed into HTTP routes automatically. The method must be exported (capitalized).
Injected Handler Parameters
Declare parameter types in any order. The framework resolves them by type:
| Type | What you get |
|---|---|
*ctx.ExecutionContext | Request-scoped context with metadata |
*ctx.Context | Legacy context (use ExecutionContext instead) |
*http.Request | Raw HTTP request |
http.ResponseWriter | Raw response writer |
ctx.Body | JSON body helper |
ctx.Query | URL query parameters |
ctx.Param | Path parameters |
ctx.Header | Request headers |
ctx.Form | Multipart/urlencoded form data |
ctx.File | Uploaded file |
ctx.Next | Call next handler (middleware pattern) |
ctx.Redirect | Redirect helper |
Binding Pipeline Layers
BindMiddleware, BindGuard, BindInterceptor, and BindExceptionFilter each take the handler func(s) to bind to. Pass no handlers to bind globally across the controller.
WebSocket Controllers
WebSocket controllers embed common.WS instead of common.REST. Method names map to WebSocket event names.
Controller Registration
Always register controllers in the module's Controllers list:
The zero value of the controller struct is passed — the framework populates injected fields through reflection.