25 lines | 1.0 KB

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 at main, no global mutable state, and axum::extract types (State, Path, Query, Json) over manual deserialisation
  • Handlers return Result<impl IntoResponse, AppError> with AppError: IntoResponse
  • Tower layers at the root: tower_http::trace::TraceLayer and tower_http::cors::CorsLayer
  • Errors: one thiserror enum whose variants map to HTTP status codes via IntoResponse; anyhow confined to bin/example crates
  • Async & state: tokio runtime, no blocking I/O in async fns (spawn_blocking when needed), connections held in a cloneable Arc-backed AppState
  • Database: sqlx with the postgres feature, compile-time-checked sqlx::query!, migrations under migrations/ via sqlx-cli

Source

Rules align with the official axum documentation: https://docs.rs/axum/latest/axum/

License

MIT