Skip to main content

Module controller

Module controller 

Source
Expand description

HTTP routing and controllers built on Hyper.

Key types: Router dispatches requests, RouteController groups routes under a base path and version, RouteDescription declares documentation, validation, and rate-limit metadata, and Middleware runs before handlers.

Request lifecycle: Hyper accepts a connection, the body, query parameters, and headers are attached to a CorrelationContext, global middlewares run, the matching route’s middlewares run, then the handler receives only the context and returns Result<ServiceResult<T>, ErrorResult>.

Handlers read input off the context (ctx.body::<T>(), ctx.header(), ctx.query_param()) and return ServiceResult or a boxed TypedServiceResult.

// ctx: CorrelationContext
// let dto = ctx.body::<CreateUser>()?;
// Ok(ServiceResult::ok("Created", dto))

Modules§

errors
Controller result helpers: shortcuts for common success and error outcomes.

Structs§

ConfigurationRegistrant
Hyper server bootstrap: owns the shared Router and the bind address. Mount controllers and global middlewares, then call ConfigurationRegistrant::serve.
DtoEntity
Documented DTO payload: its JSON Schema, example value, and Rust type name. Used for request bodies and response examples in generated documentation.
FileParameter
File-upload declaration for a multipart route: the part of the name, a description, the accepted file kind, and optional send caps enforced before the handler runs.
RouteDescription
Declarative metadata for one route: documentation, validation, and policy. A description is registered for docs generation, declares the expected request body (required when has_body is set on mount), response examples, params, file parts, rate limit, and auth notes. Build with the new constructor and the group / with_body / response / header / query_param builders.
Router
Hyper-backed route registry: stores routes with per-route middlewares, runs global middlewares for every request, and dispatches by method and path. A trailing /* on a route path acts as a prefix wildcard when matching.

Enums§

FileParameterType
Declared file-upload kind for a multipart file parameter. Determines the example extension list reported in the documentation.

Traits§

RouteController
Groups related routes under a shared base path and version. Implement RouteController::base_path and RouteController::register_routes; override RouteController::version to prefix paths with /v{version}.
RouteControllerExt
Convenience mounts that fill in this controller’s base path and version. Each mount_* takes an Fn(CorrelationContext) handler returning Result<ServiceResult<T>, ErrorResult>; the *_typed variants instead return Result<Box<dyn TypedServiceResult>, ErrorResult> for heterogeneous payloads.

Functions§

json_response
Builds a complete HTTP response from a ServiceResult<T>, setting correlation headers and the content type from the result’s response type.
typed_response
Builds a complete HTTP response from any TypedServiceResult, setting correlation headers and the content type. Serialization failures fall back to a 500 error message body.

Type Aliases§

BoxHandler
Low-level route handler used by the dispatcher: receives the prepared context plus raw headers, method, path, and body bytes, and returns a complete HTTP response.
Middleware
Pre-handler hook: inspects or mutates the context and headers, returning Ok(()) to continue or Err(ErrorResult) to short-circuit with an error response.