Axum Middleware Patterns
Simplifies the implementation of Tower and Axum middleware with best practices for ordering, state handling, and graceful shutdowns.
This skill provides specialized guidance for architecting robust Rust backend services using the Axum framework and Tower middleware ecosystem. It ensures correct middleware execution order through ServiceBuilder patterns, handles complex stateful middleware signatures, and prevents common security pitfalls like leaking authentication requirements on non-existent routes. By enforcing industry-standard patterns for tracing, CORS, and graceful shutdowns, it helps developers build production-ready APIs that are both performant and resilient.
Key Features
01ServiceBuilder implementation for intuitive top-to-bottom request ordering
02Correct stateful middleware signatures using from_fn_with_state
03Standardized graceful shutdown logic for reliable server termination
04Security-first routing using route_layer to prevent 401/403 leaks on 404 paths
05Production-ready configuration for CORS, Tracing, and Timeout layers
060 GitHub stars
Use Cases
01Implementing secure JWT authentication and authorization layers for Rust APIs
02Hardening public endpoints against resource exhaustion using timeout and limit layers
03Adding full-stack observability with request tracing and logging middleware