$ show tokio-rs/axum
axum is a Rust web framework for building HTTP APIs, focusing on ergonomics, modularity, and type safety. It provides a trait-based extractor system for request parsing (FromRequest, FromRequestParts), a composable response system (IntoResponse), and middleware layering via the Tower ecosystem. The framework is built on top of hyper and tokio, offering async request handling with support for WebSockets, Server-Sent Events, file streaming, and more. The architecture is modular, with core traits defined in the `axum-core` crate, additional features (cookies, multipart, typed headers) in `axum-extra`, and proc macros for derive patterns in `axum-macros`. The main entry point is `axum::Router`, which provides methods for routing, nesting, merging, and applying middleware layers. Handlers are async functions that accept extractor arguments (Path, Query, Json, State, etc.) and return any type implementing IntoResponse. The framework emphasizes compile-time safety through macros like `#[derive(FromRequest)]` and `#[derive(TypedPath)]`, and provides debugging aids like `#[debug_handler]` for better type error messages. It includes a rich set of examples demonstrating common patterns such as database integration, authentication, real-time communication, and error handling. External dependencies include tower and tower-http for service abstractions, hyper for HTTP parsing, serde for serialization, and tokio for async runtime. The codebase is actively maintained with a clear versioning strategy, though the main branch contains breaking changes for the upcoming 0.9 release.
The LLM identified 5 files worth highlighting for reuse:
Core trait for converting any type into an HTTP response, with blanket implementations for tuples, common types, and error handling. Demonstrates a composable response pattern that is framework-agnostic and reusable.
Custom serde deserializer for URL path parameters, supporting structs, tuples, maps, and enums. Can be extracted and used in any Rust web framework for type-safe path parameter extraction.
Implements Server-Sent Events with an event builder pattern, keep-alive, and streaming. Demonstrates a clean, composable approach to SSE that could be reused in other async Rust projects.
Provides a simple way to create middleware from an async function, encapsulating the Tower layer pattern. Demonstrates a reusable pattern for wrapping arbitrary functions as middleware.
Implements the `#[derive(FromRequest)]` proc macro, generating per-field extraction code. Demonstrates advanced Rust macro techniques for reducing boilerplate in a type-safe manner.