CodeVetter · Repo Unpack · Feature catalog
tokio-rs/axum
The principal user-facing surface is Rust APIs for routing, typed request extraction, middleware composition, and response generation. Feature flags add protocol and serialization capabilities without making every dependency mandatory. Optional crates extend the surface with cookies, typed routes, streaming formats, and compile-time diagnostics. The inspected examples demonstrate authentication, database access, forms, validation, static assets, TLS, and live connections.
- Router supports handler routes and arbitrary infallible services; repeated registration of different methods at an existing path merges MethodRouter endpoints.
- MethodRouter dispatches GET, POST, OPTIONS, PATCH, PUT, DELETE, TRACE, CONNECT, QUERY, and HEAD; HEAD falls back to GET, and unmatched methods use a fallback with configurable Allow-header handling.
- Typed inputs include Path, Query, Json, Form, State, and Multipart; Query deserializes URI parameters, Json requires an application/json-compatible content type, and Multipart parses a boundary before exposing fields.
- Handlers return IntoResponse values, including Result branches and Json; Json serialization sets application/json on success and returns a 500 text response if serialization fails.
- Middleware can wrap routers, method routers, or individual handlers; the documented Tower ecosystem supplies tracing, CORS, compression, request IDs, and timeouts, and from_fn exposes Next::run for async middleware.
- WebSocketUpgrade supports HTTP/1 upgrade and HTTP/2 CONNECT handshakes; Sse converts event streams to text/event-stream responses and can add keep-alive events.
- axum-extra offers private and signed cookies, typed headers and routing, file streams, attachments, Protobuf, JSON Lines, cached extraction, and rejection adapters; macros add TypedPath, FromRef, and debug_handler support.
- Examples expose JWT authorization, Discord OAuth login, PostgreSQL queries and user persistence, validated forms, static-file service variants, and Rustls TLS connections.