# Axum — Ergonomic Modular Web Framework for Rust > Axum is a web application framework built on Tokio, Tower, and Hyper. Focuses on ergonomics and modularity with a macro-free routing API, seamless Tower middleware integration, and type-safe extractors. The official Tokio team web framework. ## Install Save as a script file and run: ## Quick Use ```toml # Cargo.toml [dependencies] axum = "0.8" tokio = { version = "1", features = ["full"] } serde = { version = "1", features = ["derive"] } serde_json = "1" ``` ```rust use axum::{routing::{get, post}, Json, Router}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] struct Asset { repo: String, stars: u32, } async fn list_assets() -> Json> { Json(vec![ Asset { repo: "react".into(), stars: 230000 }, ]) } async fn create_asset(Json(payload): Json) -> Json { Json(payload) } #[tokio::main] async fn main() { let app = Router::new() .route("/api/assets", get(list_assets).post(create_asset)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); } ``` ## Intro Axum is a web application framework built by the Tokio team. It focuses on ergonomics and modularity with no macros — just functions and extractors. Built on top of Tokio, Tower, and Hyper, Axum integrates seamlessly with the entire Tower middleware ecosystem. - **Repo**: https://github.com/tokio-rs/axum - **Stars**: 25K+ - **Language**: Rust - **License**: MIT ## What Axum Does - **Macro-free routing** — plain function handlers - **Extractors** — type-safe request data extraction (Json, Path, Query, State) - **Tower middleware** — use any Tower middleware (timeout, rate-limit, tracing) - **WebSocket** — built-in upgrade support - **State sharing** — via Extension or State extractor - **Nested routers** — composable sub-routers - **Error handling** — typed error responses ## Comparison | Framework | Macro | Tower | Tokio-native | |---|---|---|---| | Axum | None | Full | Yes | | Rocket | Heavy | No | Own runtime | | Actix Web | Moderate | No | Own runtime | ## 常见问题 FAQ **Q: 为什么选 Axum?** A: Tokio 官方出品,和整个 Tokio 生态(Hyper、Tower、Tonic)无缝集成。如果你已经在用 Tokio,Axum 是最自然的选择。 ## 来源与致谢 Sources - Docs: https://docs.rs/axum - GitHub: https://github.com/tokio-rs/axum - License: MIT --- Source: https://tokrepo.com/en/workflows/412ff341-3634-11f1-9bc6-00163e2b0d79 Author: Script Depot