# Actix Web — Extremely Fast Web Framework for Rust > Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust. Consistently tops TechEmpower benchmarks. Built on the Actix actor framework with a rich middleware system, WebSocket support, and HTTP/2. ## Install Save in your project root: ## Quick Use ```toml # Cargo.toml [dependencies] actix-web = "4" serde = { version = "1", features = ["derive"] } ``` ```rust use actix_web::{web, App, HttpServer, HttpResponse}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] struct Asset { repo: String, stars: u32, } async fn list() -> HttpResponse { let assets = vec![Asset { repo: "react".into(), stars: 230000 }]; HttpResponse::Ok().json(assets) } async fn create(asset: web::Json) -> HttpResponse { HttpResponse::Created().json(asset.into_inner()) } #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .route("/api/assets", web::get().to(list)) .route("/api/assets", web::post().to(create)) }) .bind("0.0.0.0:8080")? .run() .await } ``` ## Intro Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust. Consistently ranked at the top of TechEmpower Framework Benchmarks. Built on the Actix actor system (though you can use it without actors). Supports HTTP/2, WebSocket, multipart, sessions, and a rich middleware ecosystem. - **Repo**: https://github.com/actix/actix-web - **Stars**: 24K+ - **Language**: Rust - **License**: Apache 2.0 + MIT ## What Actix Web Does - **Top benchmark performance** — one of the fastest web frameworks in any language - **HTTP/1.x and HTTP/2** — native support - **WebSocket** — built-in actor-based or stream-based - **Middleware** — Logger, Compress, CORS, DefaultHeaders - **Extractors** — Path, Query, Json, Form, Data (shared state) - **Static files** — actix-files - **TLS** — rustls or openssl - **Testing** — built-in test utilities ## Comparison | Framework | Speed | Ergonomics | |---|---|---| | Actix Web | Fastest | Good | | Axum | Very fast | Best | | Rocket | Fast | Very good | | Warp | Fast | Filter-based | ## 常见问题 FAQ **Q: 还有 unsafe 争议吗?** A: 早期版本有 unsafe 相关的社区争议。现在 actix-web 4.x 已经大幅减少 unsafe 使用,维护健康。 ## 来源与致谢 Sources - Docs: https://actix.rs/docs - GitHub: https://github.com/actix/actix-web - License: Apache 2.0 + MIT --- Source: https://tokrepo.com/en/workflows/412ff719-3634-11f1-9bc6-00163e2b0d79 Author: AI Open Source