Build Web Apps
Build HTTP applications with endpoint configuration, handlers, request context, and results.
The HTTP package adds web application support on top of Procyon's component and runtime model. Routes are configured by components, handlers receive a request context, and responses are returned as structured results or written directly to the response.
Web application shape
Most web applications follow this flow:
- Register controller or route configuration components.
- Implement
http.EndpointConfigurerto map endpoints. - Use
http.Handleorhttp.HandleResultto adapt handler methods. - Read request data from
http.Contextorhttp.EndpointContext. - Return an
http.Resultwhen the response should be serialized.
type HelloController struct{}
func NewHelloController() *HelloController {
return &HelloController{}
}
func (h *HelloController) ConfigureEndpoints(endpoints http.Endpoints) {
endpoints.MapGet("/hello", http.HandleResult(h.sayHello))
}
func (h *HelloController) sayHello(ctx *http.Context) (http.Result, error) {
return http.TypedResult[string]{
Body: "Hello, World!",
}, nil
}
func init() {
component.Register(NewHelloController)
}The controller is still a normal component. That means it can receive services, repositories, configuration, or other dependencies through its constructor.
Routing
Map routes with EndpointConfigurer and the Endpoints contract.
Handlers
Adapt handler methods and typed endpoint contexts.
Context
Use request, response, endpoint, and typed input data.
Results
Return structured responses from handlers.
Middleware
Hook into the request pipeline before endpoint execution.
