Latest Release: 0.2.2 (Feb 26, 2017)



Type Safe Icon (helmet)

Type Safe

From request to response Rocket ensures that your types mean something.
Learn More
Boilerplate Free Icon (robot-free)

Boilerplate Free

Spend your time writing code that really matters, and let Rocket generate the rest.
See Examples
Easy To Use Icon (sun)

Easy To Use

Rocket makes extensive use of Rust's code generation tools to provide a clean API.
Get Started
Extensible Icon (telescope)

Extensible

Easily create your own primitives that any Rocket application can use.
See How

Hello, Rocket!


This is a complete Rocket application. It does exactly what you would expect. If you were to visit http://localhost:8000/hello/John/58, you’d see:

Hello, 58 year old named John!

If someone visits a path with an <age> that isn’t a u8, Rocket doesn’t blindly call hello. Instead, it tries other matching routes or returns a 404.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#![feature(plugin)]
#![plugin(rocket_codegen)]

extern crate rocket;

#[get("/hello/<name>/<age>")]
fn hello(name: &str, age: u8) -> String {
    format!("Hello, {} year old named {}!", age, name)
}

fn main() {
    rocket::ignite().mount("/", routes![hello]).launch();
}

Forms? Check!


Handling forms is simple and easy. Simply derive FromForm for your structure and let Rocket know which parameter to use. Rocket parses and validates the form request, creates the structure, and calls your function.

Bad form request? Rocket doesn’t call your function! What if you want to know if the form was bad? Simple! Change the type of task to Option or Result!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#[derive(FromForm)]
struct Task {
   description: String,
   completed: bool
}

#[post("/", data = "<task>")]
fn new(task: Form<Task>) -> Flash<Redirect> {
    if task.get().description.is_empty() {
        Flash::error(Redirect::to("/"), "Cannot be empty.")
    } else {
        Flash::success(Redirect::to("/"), "Task added.")
    }
}

JSON, out of the box.


Rocket has first-class support for JSON, right out of the box. Simply derive Deserialize or Serialize to receive or return JSON, respectively.

Like other important features, JSON works through Rocket’s FromData trait, Rocket’s approach to deriving types from body data. It works like this: specify a data route parameter of any type that implements FromData. A value of that type will then be created automatically from the incoming request body. Best of all, you can implement FromData for your types!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#[derive(Serialize, Deserialize)]
struct Message {
   contents: String,
}

#[put("/<id>", data = "<message>")]
fn update(id: ID, message: JSON<Message>) -> JSON<SimpleMap> {
    if DB.contains_key(&id) {
        DB.insert(id, &message.contents);
        JSON(map!{ "status" => "ok" })
    } else {
        JSON(map!{ "status" => "error" })
    }
}

Rocket is ready to launch.

Get Started Learn More

And so much more.

Essential features, built in.

Templating Icon (templating-icon)

Templating

Rocket makes rendering templates a breeze with built-in templating support.
Learn More
Cookies Icon (cookies-icon)

Cookies

Cookies are first-class in Rocket. View, add, or remove cookies without hassle.
Learn More
Streams Icon (streams-icon)

Streams

Rocket streams all incoming and outgoing data, so size isn't a concern.
Learn More

Config Environments Icon (config-icon)

Config Environments

Configure your application your way for development, staging, and production.
Learn More
Query Params Icon (query-icon)

Query Params

Handling query parameters isn’t an afterthought in Rocket.
Learn More
Testing Library Icon (testing-icon)

Testing Library

Unit test your applications with ease using the built-in testing library.
Learn More