Rocket in the landscape
Understand where the Rocket web framework fits among Rust backend tools, how its attribute-macro design differs from Axum, and when its style works well.
A beginner coming to Rust backends hears about Axum, Actix-web, and Rocket as the three names people say first. Rocket takes a very different approach to building a server.
Rocket is older than Axum. It was one of the first Rust web frameworks that tried to make server programming feel friendly and high-level. That goal shaped everything about it. The way you write a Rocket application looks noticeably different from the way you write an Axum application, even when both apps do the same thing.
Rocket's core idea - write less with attribute macros
Rocket's most visible feature is that it uses Rust's attribute macros to attach routing information directly to functions.
An attribute macro is a special Rust tool that lets a library process the code that comes after it. You write something like #[get("/")] above a function, and Rocket reads that annotation at compile time. It turns the function into a handler for a GET request to the path /.
This feels convenient. The route lives right next to the function that handles it. You do not need a separate router setup block that lists all your routes in one place, like Axum uses.
Here is the smallest possible Rocket application. You can see the macro style immediately.
// main.rs
#[macro_use]
extern crate rocket;
#[get("/")]
fn index() -> &'static str {
"Hello from Rocket!"
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![index])
}
A few details stand out. The #[get("/")] macro turns index into a route. The #[launch] macro sets up the async runtime and starts the server for you. And routes![index] is another macro that collects the handler into a list Rocket can mount.
Compare this to the Axum version: a plain async function returning a string, registered on a router with Router::new().route("/", get(hello)) - no macro, no attribute, and the return type is inferred from the function itself.
// main.rs
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello from Axum!" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Axum builds the route list explicitly inside main using the Router type. Rocket attaches routing information to each handler function and then mounts the handlers with a small macro. Neither style is objectively better, but the difference matters. The macro approach hides some setup from view. The explicit approach shows every piece.
Macros Are Not Magic:
An attribute macro still generates ordinary Rust code. When you write #[get("/")], Rocket generates code that builds a Route object behind the scenes. The macro changes how you read and write the application, but the final compiled program contains the same kind of routing data a manual setup would create.
Why Rocket exists and what problem it solves
Before Rocket appeared, writing a Rust server often meant handling low-level HTTP parsing yourself. Hyper existed, but it is a low-level HTTP library, not a friendly framework for building a full application quickly. You could wire up routing by hand, but the code became repetitive and easy to get wrong.
Rocket wanted to bring a framework experience closer to languages like Python's Flask or Ruby's Sinatra. The developer should describe what each endpoint does, and the framework should handle the wiring, parsing, and routing.
Rocket also marketed itself around a concept it called type safety without boilerplate. The idea was that the types in your handler signatures should do more work. If you want a path segment as a number, you write id: u32, and Rocket parses the URL segment into that number before calling your function. If parsing fails, the request never reaches your handler.
Axum shares this type-driven extractor idea, but Rocket pushes it into the route macro itself. A Rocket route can declare its path parameters directly inside the macro.
// main.rs
#[macro_use]
extern crate rocket;
#[get("/users/<id>")]
fn get_user(id: u32) -> String {
format!("Looking up user number {}", id)
}
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello, {}!", name)
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![get_user, hello])
}
The route string "/users/<id>" tells Rocket to expect a path segment after /users/. Rocket looks at the function parameter named id, sees it is a u32, and parses the URL segment accordingly. A request to /users/42 works. A request to /users/not-a-number does not reach the handler at all: the segment fails to parse as a u32, so the route does not match, and - with no other matching route - Rocket answers with a 404.
In Axum, you would express the same thing with a Path extractor.
// main.rs
use axum::{extract::Path, routing::get, Router};
async fn get_user(Path(id): Path<u32>) -> String {
format!("Looking up user number {}", id)
}
async fn hello(Path(name): Path<String>) -> String {
format!("Hello, {}!", name)
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/users/{id}", get(get_user))
.route("/hello/{name}", get(hello));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Both frameworks use the Rust type system to parse inputs safely. Rocket embeds the parameter names in the route path macro. Axum separates the route path from the extractor argument. Beginners often find the Rocket version more readable because the path and the types sit close together. Others prefer Axum because there is less macro involvement.
Rocket 0.5 works on stable Rust - older versions did not:
Rocket 0.4 and earlier required the nightly Rust compiler for their compile-time features. Rocket 0.5 (November 2022) was the first version that works on stable Rust, and every version since - including the current 0.5.2 (23 October 2026), which requires Rust 1.89 or newer (declared in its published Cargo.toml). If you see a nightly requirement in Rocket documentation, check which Rocket version the document is for: the official guide pages for v0.3 and v0.4 still say nightly, because they describe those old versions, not 0.5.
The launch macro and the server setup
Rocket's #[launch] attribute wraps the entire server startup. Inside the function, you build the Rocket instance, mount routes, attach configuration, and return the built value. Rocket then owns the async runtime and the TCP listener for you.
Here is a slightly richer Rocket setup with two routes under one mount and a custom port from a configuration file.
// main.rs
#[macro_use]
extern crate rocket;
#[get("/")]
fn home() -> &'static str {
"Home page"
}
#[get("/about")]
fn about() -> &'static str {
"About page"
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![home, about])
}
Rocket reads a file named Rocket.toml from your project root for configuration. A typical file looks like this:
# Rocket.toml
[default]
port = 8000
address = "127.0.0.1"
When you run cargo run, Rocket starts listening on port 8000. You did not write any socket binding code, any async runtime setup, or any error handling for the listener. The #[launch] macro generated all of that.
Axum deliberately makes this setup visible. You bind a TcpListener, you start the Tokio runtime with #[tokio::main], and you call axum::serve. Axum assumes you want control over these pieces. Rocket assumes you want them handled for you.
Neither assumption is wrong. Teams that need to customize the server lifecycle often prefer Axum's explicit style. Teams that want a working server as quickly as possible often like Rocket's approach.
If You See This Output, Rocket Is Working:
When you run a Rocket app, the terminal shows a message similar to Rocket has launched from http://127.0.0.1:8000. If you visit that URL and see your handler's text, the macro-generated setup worked correctly.
How Rocket handles guards - middleware in a different shape
Axum uses the Tower Service and Layer system for middleware. Rocket uses a concept called request guards.
A request guard is a type that runs before a handler and either allows the request to continue or rejects it. For example, you can create a guard that checks an API key in a header.
// main.rs
#[macro_use]
extern crate rocket;
use rocket::http::Status;
use rocket::request::{FromRequest, Outcome};
use rocket::Request;
struct ApiKey(String);
#[rocket::async_trait]
impl<'r> FromRequest<'r> for ApiKey {
type Error = ();
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
match request.headers().get_one("x-api-key") {
Some(key) => Outcome::Success(ApiKey(key.to_string())),
None => Outcome::Error((Status::Unauthorized, ())),
}
}
}
#[get("/secret")]
fn secret(key: ApiKey) -> String {
format!("Access granted with key {}", key.0)
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![secret])
}
The ApiKey guard looks at the incoming request. If the header x-api-key exists, the guard succeeds and the handler runs. If the header is missing, Rocket returns a 401 Unauthorized response without calling the handler.
In Axum, the equivalent middleware would use middleware::from_fn or a Tower layer. The concept is the same - run logic before the handler - but Rocket's guard model is tied to its request type and its own trait system. Axum's middleware reuses the Tower ecosystem.
Rocket Guards Are Not Tower Middleware:
If you write a Rocket request guard, it works inside Rocket applications. You cannot take that guard and reuse it in an Axum app or a Hyper service. Axum's middleware, by contrast, can often be shared with any Tower-based project. This lock-in matters if you plan to mix frameworks or build reusable infrastructure libraries.
Rocket's state management compared to Axum
Rocket also has its own way to share application state. You attach state to the Rocket instance and then declare a &State<AppState> parameter in your handler.
// main.rs
#[macro_use]
extern crate rocket;
use rocket::State;
struct AppState {
app_name: String,
}
#[get("/name")]
fn name(state: &State<AppState>) -> String {
format!("Application: {}", state.app_name)
}
#[launch]
fn rocket() -> _ {
rocket::build()
.manage(AppState {
app_name: "My Rocket App".to_string(),
})
.mount("/", routes![name])
}
The .manage() call tells Rocket to hold onto an instance of AppState. Handlers that need it add &State<AppState> as a parameter. Rocket retrieves the managed value automatically.
Axum's equivalent uses the State extractor with a Router::with_state call.
// main.rs
use axum::{extract::State, routing::get, Router};
use std::sync::Arc;
struct AppState {
app_name: String,
}
async fn name(State(state): State<Arc<AppState>>) -> String {
format!("Application: {}", state.app_name)
}
#[tokio::main]
async fn main() {
let state = Arc::new(AppState {
app_name: "My Axum App".to_string(),
});
let app = Router::new()
.route("/name", get(name))
.with_state(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Both frameworks solve the same problem. Rocket's version hides the Arc wrapper because Rocket manages sharing internally. Axum asks you to wrap shared state in Arc yourself, which is an explicit reminder that the state is shared across many concurrent requests.
Beginners often find Rocket's managed state easier to read because &State<AppState> is a very natural signature. Axum's State<Arc<AppState>> looks more intimidating at first but teaches you about concurrency and ownership sooner.
Rocket's form handling and multipart support
Rocket has historically been strong in handling HTML form submissions and file uploads. The framework's design anticipates server-rendered web applications, not just JSON APIs.
Here is a Rocket handler that accepts a form submission.
// main.rs
#[macro_use]
extern crate rocket;
use rocket::form::Form;
#[derive(FromForm)]
struct LoginForm {
username: String,
password: String,
}
#[post("/login", data = "<form>")]
fn login(form: Form<LoginForm>) -> String {
format!(
"Login attempt for user '{}'",
form.username
)
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![login])
}
The #[derive(FromForm)] macro tells Rocket how to parse the submitted form data into the LoginForm struct. The data = "<form>" part of the route macro says that this handler expects form data in the request body. Rocket validates and parses it before calling the handler.
Axum can also handle forms through the Form extractor, and it needs no extra setup: form is one of axum's default features, so axum::extract::Form works out of the box with a plain axum = "0.8" dependency. The difference is style, not availability - Axum's version leans on Serde, while Rocket's leans on its own FromForm derive.
// main.rs
use axum::{extract::Form, routing::post, Router};
use serde::Deserialize;
#[derive(Deserialize)]
struct LoginForm {
username: String,
password: String,
}
async fn login(Form(form): Form<LoginForm>) -> String {
format!("Login attempt for user '{}'", form.username)
}
#[tokio::main]
async fn main() {
let app = Router::new().route("/login", post(login));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Rocket's form story was one of its early selling points. If you are building a traditional server-rendered application with HTML forms, Rocket's macros make that workflow feel very natural. Axum handles it well too, but the setup leans more on Serde and less on Rocket-style code generation.
Rocket's version history and stability notes
Rocket has gone through several major versions, and the API has changed between them. Code written for Rocket 0.4 will not compile on Rocket 0.5 without modifications. Rocket 0.5 (November 2022) is the first version that works on stable Rust, which was a significant milestone after years of requiring nightly. The 0.5 line is still current: 0.5.1 arrived in May 2024, and the latest release is 0.5.2 (23 October 2026). Add it as rocket = "0.5.2" in Cargo.toml.
Axum has also had breaking changes, but its release cycle is tied closely to the Tokio and Hyper ecosystems. Because Axum's API surface is smaller and more explicit, version upgrades tend to be more mechanical: rename a few types, adjust a few signatures. Rocket's macro-heavy API can make upgrades more involved because the generated code is less visible.
If you are reading old Rocket tutorials, watch for syntax differences. Rocket 0.4 examples usually start the server with rocket::ignite().mount("/", routes![...]).launch() instead of the #[launch] macro, and they pull JSON, templates, and other extras from a separate rocket_contrib crate that no longer exists in 0.5 - those features are now built-in or in their own crates (rocket_dyn_templates, rocket_db_pools). The Rust web framework ecosystem has matured quickly, and Rocket has adapted along the way.
Old Rocket Examples May Not Compile:
Rocket's API has changed substantially across versions. If you copy a snippet from a 2018 or 2020 blog post, it may use an older macro syntax or a different type name. Always verify the Rocket version the example targets before assuming the code is wrong when it fails to compile.
Comparing Rocket's design philosophy to Axum
The essential difference between the two frameworks is a question of visibility versus convenience.
Axum shows you the pieces. You see the Router, you see the route methods, you see the extractor types, you see the serve call. This explicitness means less magic, but it also means more code to read when you are starting out.
Rocket hides the pieces. The #[get] macro handles routing. The #[launch] macro handles startup. Guards handle pre-handler logic. Managed state handles sharing. This convenience means less boilerplate, but it also means you have to trust the framework's generated code and understand Rocket's specific concepts.
For an absolute beginner, Rocket can feel friendlier at first because a complete server fits in very few lines. For a developer who wants to understand exactly what is happening or needs to integrate with the broader Tower ecosystem, Axum's transparency is valuable.
Here is a side-by-side summary of the same tiny app in both frameworks. Read them together: the Rocket version is shorter because the framework supplies the server, the routing, and the launch code behind its macros; the Axum version spells each of those steps out.
Rocket:
// Rocket main.rs
#[macro_use]
extern crate rocket;
#[get("/")]
fn hello() -> &'static str {
"Hello from Rocket"
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![hello])
}
Axum:
// Axum main.rs
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello from Axum" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
The Rocket version has no visible async runtime, no visible listener, no visible router construction. The Axum version lays those out explicitly. Which you prefer depends on whether you value fewer lines or more clarity about the moving parts.
Rocket's ecosystem and middleware situation
Rocket does not use Tower middleware. It has its own guard system, its own fairing system, and its own way to add functionality at various stages of the request lifecycle.
This means Rocket applications cannot directly use Tower middleware libraries like tower-http for compression, tracing, or CORS. Axum gets those integrations for free because it is built on Tower. Rocket either provides equivalents in its own ecosystem or you write a Rocket-specific guard or fairing.
The practical consequence is that Axum tends to have a wider range of reusable middleware available, especially for infrastructure concerns like observability and rate limiting. Rocket's ecosystem is smaller but often tightly integrated with Rocket's design. When you find a Rocket-specific crate, it usually works well because it follows Rocket's conventions.
If you already use Tower-based tools elsewhere in a Rust project - perhaps for gRPC services with Tonic or for custom network services - Axum lets you share middleware across all of them. Rocket's middleware stays inside Rocket.
When Rocket fits well
Rocket is a strong choice when your team wants rapid development of server-rendered applications, HTML forms, and traditional web app backends. Its form handling, templating support, and managed state make building a multi-page site straightforward.
Rocket also suits beginners who are learning Rust and want to see a working server without first understanding async runtimes, TCP listeners, and Tower services. The macro-based approach gets a server running very quickly.
For teams already invested in the Tokio ecosystem, building JSON APIs, microservices, or applications that need fine-grained control over the server lifecycle, Axum often fits better. Axum's explicit design integrates cleanly with the tools those teams already use.
Neither framework is disappearing. Rocket remains maintained and has a loyal user base. Axum's adoption has grown partly because of its Tokio team backing and its Tower compatibility, but Rocket continues to be a legitimate option with its own advantages.
The Landscape Has Room for Both:
Rust backend development is not a winner-take-all situation. Teams choose frameworks based on their existing infrastructure, their team's experience, and the type of application they are building. Rocket and Axum coexist because they optimize for different trade-offs.
Summary
Rocket's story is about a framework that pushed Rust web development toward a higher-level, macro-driven, "just write the handler" experience. Its influence helped shape expectations for what a Rust web framework could feel like. Axum learned from that era and chose a different path: less magic, more explicit composition, deeper integration with the Tower ecosystem.
The most useful takeaway is not that one framework is better, but that the Rust web ecosystem offers different philosophies. Rocket optimizes for a self-contained, convenient developer experience. Axum optimizes for transparency and composability. Your project's needs determine which philosophy fits. If you are building a server-rendered application and want rapid iteration with minimal boilerplate, Rocket deserves serious consideration. If you are building a JSON API within a Tokio-centric infrastructure, Axum's design will feel more natural.