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§
- Configuration
Registrant - Hyper server bootstrap: owns the shared
Routerand the bind address. Mount controllers and global middlewares, then callConfigurationRegistrant::serve. - DtoEntity
- Documented DTO payload: its JSON Schema, example value, and Rust type name. Used for request bodies and response examples in generated documentation.
- File
Parameter - 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.
- Route
Description - Declarative metadata for one route: documentation, validation, and policy.
A description is registered for docs generation, declares the expected request
body (required when
has_bodyis set on mount), response examples, params, file parts, rate limit, and auth notes. Build with thenewconstructor and thegroup/with_body/response/header/query_parambuilders. - 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§
- File
Parameter Type - Declared file-upload kind for a multipart file parameter. Determines the example extension list reported in the documentation.
Traits§
- Route
Controller - Groups related routes under a shared base path and version.
Implement
RouteController::base_pathandRouteController::register_routes; overrideRouteController::versionto prefix paths with/v{version}. - Route
Controller Ext - Convenience mounts that fill in this controller’s base path and version.
Each
mount_*takes anFn(CorrelationContext)handler returningResult<ServiceResult<T>, ErrorResult>; the*_typedvariants instead returnResult<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 orErr(ErrorResult)to short-circuit with an error response.