What problem does it solve?
This Skill prevents common Axum/Tower middleware wiring mistakes that either fail to compile or silently skip your handler logic. It also avoids subtle routing bugs where an auth gate incorrectly converts missing routes into unauthorized responses.
Core Features & Use Cases
- Correct middleware helper selection: choose
map_request/map_response for one-way transforms and from_fn/from_fn_with_state when you need request+response handling or short-circuiting.
- Guaranteed
from_fn argument ordering: enforces the required shape of [FromRequestParts..., FromRequest, Next] to avoid opaque Handler is not satisfied trait-bound errors.
- Safe control flow with
Next: ensures middleware either calls next.run(request).await or deliberately short-circuits with an IntoResponse, avoiding “handler never runs” incidents.
- Correct
.layer() vs .route_layer() semantics: uses .route_layer() for auth/authz so unmatched paths still return real 404 instead of being masked as 401/403.
- Layer stacking without reversal confusion: clarifies how Router’s chained
.layer() order differs from tower::ServiceBuilder, preventing request/response execution order surprises.
Quick Start
Add middleware to your Axum routes by asking for a from_fn or from_fn_with_state example that uses the correct argument order, short-circuit behavior, and .route_layer() for auth gates on Axum 0.7/0.8.