# Rocket — A Web Framework for Rust with Focus on Usability > Rocket is a web framework for Rust that makes it simple to write fast, type-safe, secure web applications. Focuses on usability with derive macros, type-safe routing, request guards, and managed state. Intuitive yet powerful. ## Install Save in your project root: ## Quick Use ```toml # Cargo.toml [dependencies] rocket = "0.5" serde = { version = "1", features = ["derive"] } rocket_dyn_templates = { version = "0.2", features = ["tera"] } ``` ```rust #[macro_use] extern crate rocket; use rocket::serde::{json::Json, Deserialize, Serialize}; #[derive(Serialize, Deserialize)] #[serde(crate = "rocket::serde")] struct Asset { repo: String, stars: u32, } #[get("/api/assets")] fn list() -> Json> { Json(vec![ Asset { repo: "react".into(), stars: 230000 }, Asset { repo: "vue".into(), stars: 210000 }, ]) } #[post("/api/assets", format = "json", data = "")] fn create(asset: Json) -> Json { Json(asset.into_inner()) } #[launch] fn rocket() -> _ { rocket::build().mount("/", routes![list, create]) } ``` ## Intro Rocket is a web framework for Rust that makes it simple to write fast, type-safe, secure web applications with incredible usability. Uses Rust macros and the type system to ensure correctness at compile time. Created by Sergio Benitez. - **Repo**: https://github.com/rwf2/Rocket - **Stars**: 25K+ - **Language**: Rust - **License**: MIT + Apache 2.0 ## What Rocket Does - **Type-safe routing** — routes validated at compile time - **Request guards** — type-based access to request data - **Data guards** — typed request body parsing - **Fairings** — middleware-like lifecycle callbacks - **Managed state** — thread-safe shared state - **Templates** — Tera, Handlebars via rocket_dyn_templates - **Async** — fully async since Rocket 0.5 - **Forms** — multipart, validated form handling - **Testing** — built-in local Client for tests ## Comparison | Rust Framework | Style | Async | Macro-heavy | |---|---|---|---| | Rocket | Rails-like | Yes (0.5+) | Yes | | Axum | Tower-based | Yes | No | | Actix Web | Actor | Yes | Moderate | | Warp | Filter combinators | Yes | No | ## 常见问题 FAQ **Q: Rocket vs Axum?** A: Rocket 更 opinionated、开发速度快(Rails-like DX);Axum 更模块化、和 Tokio/Tower 生态无缝集成。 ## 来源与致谢 Sources - Docs: https://rocket.rs/guide - GitHub: https://github.com/rwf2/Rocket - License: MIT + Apache 2.0 --- Source: https://tokrepo.com/en/workflows/412ff08d-3634-11f1-9bc6-00163e2b0d79 Author: AI Open Source