Expand description
§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
rocket_contrib
documentation, which contains
automatic JSON (de)serialiazation, templating support, static file serving,
and other useful features.
§Libraries
Rocket’s functionality is split into two crates:
- Core - This core library. Needed by every Rocket application.
- Contrib - Provides useful functionality for many Rocket applications. Completely optional.
§Usage
First, depend on rocket
in Cargo.toml
:
[dependencies]
rocket = "0.4.11"
Then, add the following to the top of your main.rs
file:
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] 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(proc_macro_hygiene, decl_macro)]
#[macro_use] 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
integration testing of a Rocket application. The top-level local
module
documentation and the testing chapter of the guide include detailed
examples.
Modules§
- Application configuration and configuration parameter retrieval.
- Types and traits for handling incoming body data.
- Types representing various errors that can occur in a Rocket application.
- Fairings: callbacks at attach, launch, request, and response time.
- Types and traits for request and error handlers and their return values.
- Types that map to concepts in HTTP.
- Structures for local dispatching of requests, primarily for testing.
- Success, failure, and forward handling.
- Types and traits for request parsing and handling.
- Types and traits to build and send responses.
Macros§
- Generates a [
Vec
] ofCatcher
s from a set of catcher paths. - Generates a [
Vec
] ofRoute
s from a set of route paths. - Type safe generation of route URIs.
Structs§
- An error catching route.
- Structure for Rocket application configuration.
- Type representing the data in the body of an incoming request.
- The type of an incoming web request.
- A response, as returned by types implementing
Responder
. - The main
Rocket
type: used to mount routes and catchers and launch the application. - A route: a method, its handler, path, rank, and format/media type.
- Request guard to retrieve managed state.
Enums§
- An enum representing success (
Success
), failure (Failure
), or forwarding (Forward
).
Traits§
- Trait implemented by types that can handle requests.
Functions§
- Alias to
Rocket::custom()
. Creates a new instance ofRocket
with a custom configuration. - Alias to
Rocket::ignite()
Creates a new instance ofRocket
.
Type Aliases§
- The type of an error handler.
Attribute Macros§
- Attribute to generate a
Catcher
and associated metadata. - Attribute to generate a
Route
and associated metadata. - Attribute to generate a
Route
and associated metadata. - Attribute to generate a
Route
and associated metadata. - Attribute to generate a
Route
and associated metadata. - Attribute to generate a
Route
and associated metadata. - Attribute to generate a
Route
and associated metadata. - Attribute to generate a
Route
and associated metadata. - Attribute to generate a
Route
and associated metadata.
Derive Macros§
- Derive for the
FromForm
trait. - Derive for the
FromFormValue
trait. - Derive for the
Responder
trait. - Derive for the
UriDisplay<Path>
trait. - Derive for the
UriDisplay<Query>
trait.