rust-axum
Idiomatic axum 0.8 service rules: layered tower, tracing, thiserror, sqlx, async-first.
npx rulepack add rust-axum
What it covers
- Routing:
Router::new()per module composed atmain, no global mutable state, andaxum::extracttypes (State,Path,Query,Json) over manual deserialisation - Handlers return
Result<impl IntoResponse, AppError>withAppError: IntoResponse - Tower layers at the root:
tower_http::trace::TraceLayerandtower_http::cors::CorsLayer - Errors: one
thiserrorenum whose variants map to HTTP status codes viaIntoResponse;anyhowconfined to bin/example crates - Async & state:
tokioruntime, no blocking I/O in async fns (spawn_blockingwhen needed), connections held in a cloneableArc-backedAppState - Database:
sqlxwith thepostgresfeature, compile-time-checkedsqlx::query!, migrations undermigrations/viasqlx-cli
Source
Rules align with the official axum documentation: https://docs.rs/axum/latest/axum/
License
MIT