Expand description
Request-lifecycle middleware utilities and Tower layer factories.
This module provides utilities that operate at request time, not at route registration time. These are Tower layer factories — they produce middleware that wraps individual routes or entire routers.
§Module Boundaries
pipeline.rs— build-time: compose routes into aRoutercontroller.rs— build-time: declare which handlers belong to a controllermiddleware.rs— request-time: inspect/modify requests and responses
§Protected Route Groups
Auth is a cross-cutting concern — it belongs here as a router transform,
not inside a controller handler. Apply it to a route group via .map():
ⓘ
RouterPipeline::new()
.mount_guarded::<AdminController, _>(admin_svc, || { /* config check */ })
.map(require_bearer(admin_key))Or scoped to just a sub-group:
ⓘ
RouterPipeline::new()
.group("/admin", |g| g
.mount::<AdminController>(admin_svc)
.map(require_bearer(admin_key)) // only admin routes are protected
)Functions§
- guard
- Returns a
Router -> Routertransform that guards every request with a predicate. - require_
bearer - Returns a
Router -> Routertransform that enforcesAuthorization: Bearer <token>on every request passing through the router it is applied to.