CodeVetter · Repo Unpack · Extension points
tokio-rs/axum
Extensions are expressed through Rust traits, router builders, Cargo features, and generated implementations. Applications can add typed request inputs and outputs without changing the router internals. Tower services and layers supply middleware composition, while Listener and Executor customize serving within the Tokio/Hyper architecture. axum-extra and axum-macros provide additional integration points for typed routes, cookies, and generated extraction.
- Implement FromRequestParts<S> for metadata-only inputs or FromRequest<S> for body-consuming inputs; both define an IntoResponse rejection and receive application state.
- Implement IntoResponse for domain outputs and errors; its Result implementation converts either branch, allowing application errors to remain HTTP responses rather than Tower service failures.
- Router::route_service accepts cloneable infallible Tower services with IntoResponse outputs, while PathRouter merges method registrations at the same path.
- Tower Layer can wrap individual handlers through Handler::layer; from_fn middleware receives a Next continuation that executes the remaining service stack.
- FromRef connects aggregate application state to substates; the OAuth example independently extracts MemoryStore and BasicClient from AppState, and axum-macros exposes a FromRef derive.
- TypedPath links a handler's first argument to a route, derives capture-compatible extraction and percent-encoded Display output, and supports custom rejections; vpath! separately validates static path syntax at compile time.
- Custom Listener implementations choose IO/address types and own accept-error retry behavior; ListenerExt adds connection limits, while Serve::with_executor substitutes an Executor returning Tokio JoinHandles.
- FromRequest derives accept container-level via, rejection, and state attributes; expansion chooses explicit state or infers it from fields and delegation, providing a generated-wrapper extension path.