[][src]Crate rocket

Rocket - Core API Documentation

Hello, and welcome to the core Rocket API documentation!

This API documentation is highly technical and is purely a reference. There's an overview of Rocket on the main site as well as a full, detailed guide. If you'd like pointers on getting started, see the quickstart or getting started chapters of the guide.

You may also be interested in looking at the contrib API documentation, which contains JSON and templating support, among other features.

Libraries

Rocket's functionality is split into three crates:

  1. Core - The core library. Needed by every Rocket application.
  2. Codegen - Core code generation plugin. Should always be used alongsize rocket, though it's not necessary.
  3. Contrib - Provides useful functionality for many Rocket applications. Completely optional.

Usage

The sanctioned way to use Rocket is via the code generation plugin. This makes Rocket easier and safer to use and allows a somewhat stable API as Rocket matures. To use Rocket with the code generation plugin in your Cargo-based project, add the following to Cargo.toml:

This example is not tested
[dependencies]
rocket = "*"
rocket_codegen = "*"

If you'll be deploying your project to crates.io, you'll need to change the "*" to the current version of Rocket.

Then, add the following to the top of your main.rs file:

#![feature(plugin)]
#![plugin(rocket_codegen)]

extern crate rocket;

See the guide for more information on how to write Rocket applications. Here's a simple example to get you started:

#![feature(plugin)]
#![plugin(rocket_codegen)]

extern crate rocket;

#[get("/")]
fn hello() -> &'static str {
    "Hello, world!"
}

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

Configuration

Rocket and Rocket libraries are configured via the Rocket.toml file and/or ROCKET_{PARAM} environment variables. For more information on how to configure Rocket, see the configuration section of the guide as well as the config module documentation.

Testing

The local module contains structures that facilitate unit and itegration testing of a Rocket application. The top-level local module documentation and the testing chapter of the guide include detailed examples.

Modules

config

Application configuration and configuration parameter retrieval.

data

Types and traits for handling incoming body data.

error

Types representing various errors that can occur in a Rocket application.

fairing

Fairings: callbacks at attach, launch, request, and response time.

handler

The types of request and error handlers and their return values.

http

Types that map to concepts in HTTP.

local

Structures for local dispatching of requests, primarily for testing.

outcome

Success, failure, and forward handling.

request

Types and traits for request parsing and handling.

response

Types and traits to build and send responses.

Structs

Catcher

An error catching route.

Config

Structure for Rocket application configuration.

Data

Type representing the data in the body of an incoming request.

Request

The type of an incoming web request.

Response

A response, as returned by Responders.

Rocket

The main Rocket type: used to mount routes and catchers and launch the application.

Route

A route: a method, its handler, path, rank, and format/media type.

State

Request guard to retrieve managed state.

Enums

Error

[unstable] Error type for Rocket. Likely to change.

Outcome

An enum representing success (Success), failure (Failure), or forwarding (Forward).

Functions

custom

Alias to Rocket::custom(). Creates a new instance of Rocket with a custom configuration.

ignite

Alias to Rocket::ignite(). Creates a new instance of Rocket.

Type Definitions

ErrorHandler

The type of an error handler.

Handler

The type of a request handler.