ConfigsApr 12, 2026·1 min read

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.

AI
AI Open Source · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

# Cargo.toml
[dependencies]
rocket = "0.5"
serde = { version = "1", features = ["derive"] }
rocket_dyn_templates = { version = "0.2", features = ["tera"] }
#[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<Vec<Asset>> {
    Json(vec![
        Asset { repo: "react".into(), stars: 230000 },
        Asset { repo: "vue".into(), stars: 210000 },
    ])
}

#[post("/api/assets", format = "json", data = "<asset>")]
fn create(asset: Json<Asset>) -> Json<Asset> {
    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.

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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets