Opinionated starter template for a small-but-real Rust API using:
axumfor HTTP routingutoipa+utoipa-swagger-uifor OpenAPI + Swagger UItracing+tower-httpfor request logging
Run the server:
cargo runThen open:
- API:
http://localhost:8000/hello - Swagger UI:
http://localhost:8000/swagger-ui - OpenAPI JSON:
http://localhost:8000/api-docs/openapi.json
This template keeps the responsibilities separated so your codebase scales cleanly:
src/
├── main.rs # app wiring (router, middleware, server)
├── api_docs.rs # OpenAPI registry (paths + schemas)
├── routes/ # route definitions only (no business logic)
├── handlers/ # HTTP layer: request -> service -> response
├── models/ # request/response DTOs (serde + ToSchema)
└── services/ # business logic (add when needed)
Typical flow:
- Add a response/request model (if needed) in
src/models/... - Add a handler function in
src/handlers/...and annotate it with#[utoipa::path(...)] - Add the route in
src/routes/... - Register the handler + schemas in
src/api_docs.rs
By default the server initializes tracing_subscriber in src/main.rs.
If you want to override logging at runtime:
RUST_LOG="hello_api=info,tower_http=debug" cargo run