Cette page est affichée en anglais. Une traduction française est en cours.
SkillsApr 12, 2026·2 min de lecture

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.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
step-1.md
Commande d'installation directe
npx -y tokrepo@latest install 412ff08d-3634-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

TL;DR
Rocket is a Rust web framework that uses derive macros and type-safe routing for fast, secure web applications.
§01

What it is

Rocket is a web framework for Rust that prioritizes usability without sacrificing speed or safety. It uses derive macros and type-safe routing to catch errors at compile time rather than runtime.

Rocket targets Rust developers building web APIs and applications who want a framework with ergonomic request handling, built-in form validation, and managed state -- similar to Flask or Express but with Rust compile-time guarantees.

§02

How it saves time or tokens

Rocket eliminates boilerplate through derive macros. Route handlers are plain functions annotated with #[get], #[post], etc. Request guards handle authentication and validation declaratively, so you do not write middleware chains manually. Type mismatches are caught at compile time.

§03

How to use

  1. Add Rocket to your Cargo.toml:
[dependencies]
rocket = "0.5"
serde = { version = "1", features = ["derive"] }
  1. Write route handlers as annotated functions.
  1. Mount routes and launch the server with #[launch].
§04

Example

#[macro_use] extern crate rocket;
use rocket::serde::{json::Json, Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
#[serde(crate = "rocket::serde")]
struct Task {
    name: String,
    done: bool,
}

#[get("/tasks")]
fn list() -> Json<Vec<Task>> {
    Json(vec![
        Task { name: 'Build API'.into(), done: false },
    ])
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![list])
}
§05

Related on TokRepo

§06

Common pitfalls

  • Rocket 0.5 requires Rust nightly for some features. Check which features work on stable before committing to a toolchain.
  • The #[launch] macro sets up the async runtime. Do not create your own tokio runtime alongside it.
  • Rocket uses its own serde re-export. Use #[serde(crate = "rocket::serde")] to avoid version conflicts with a top-level serde dependency.

Questions fréquentes

Does Rocket require Rust nightly?+

Rocket 0.5 works on stable Rust for core features. Some advanced features like certain proc macros may benefit from nightly. Check the Rocket changelog for the latest stable compatibility status.

How does Rocket compare to Actix Web?+

Actix Web focuses on raw performance and uses an actor-based model. Rocket focuses on developer ergonomics with derive macros and compile-time route checking. Both are production-ready Rust web frameworks with different design philosophies.

What is a request guard in Rocket?+

A request guard is a type that implements the FromRequest trait. Rocket automatically validates and extracts data from incoming requests. Guards handle authentication, content negotiation, and custom validation declaratively.

Does Rocket support WebSockets?+

Rocket 0.5 includes WebSocket support through the rocket_ws crate. It provides a typed API for WebSocket connections that integrates with Rocket request guards and managed state.

Can Rocket serve static files?+

Yes. Rocket provides the FileServer handler for serving static files from a directory. Mount it at a path like rocket::fs::FileServer::from('static') and Rocket handles caching headers and MIME types.

Sources citées (3)

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires