Crate rocket[−][src]
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.
Usage
Depend on rocket in Cargo.toml:
[dependencies]
rocket = "0.5.0-rc.1"
Note that development versions, tagged with -dev, are not published
and need to be specified as git dependencies.
See the guide for more information on how to write Rocket applications. Here’s a simple example to get you started:
#[macro_use] extern crate rocket; #[get("/")] fn hello() -> &'static str { "Hello, world!" } #[launch] fn rocket() -> _ { rocket::build().mount("/", routes![hello]) }
Features
To avoid compiling unused dependencies, Rocket gates certain features, all of which are disabled by default:
| Feature | Description |
|---|---|
secrets | Support for authenticated, encrypted private cookies. |
tls | Support for TLS encrypted connections. |
json | Support for JSON (de)serialization. |
msgpack | Support for MessagePack (de)serialization. |
uuid | Support for UUID value parsing and (de)serialization. |
Features can be selectively enabled in Cargo.toml:
[dependencies]
rocket = { version = "0.5.0-rc.1", features = ["secrets", "tls", "json"] }
Configuration
Rocket offers a rich, extensible configuration system built on Figment. By
default, Rocket applications are configured via a Rocket.toml file
and/or ROCKET_{PARAM} environment variables, but applications may
configure their own sources. See the configuration guide for full details.
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 guide include detailed examples.
Re-exports
pub use futures; | |
pub use tokio; | |
pub use figment; |
Modules
| catcher | Types and traits for error catchers and their handlers and return types. |
| config | Server and application configuration. |
| 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 launch, liftoff, request, and response time. |
| form | Parsing and validation of HTTP forms and fields. |
| fs | File serving, file accepting, and file metadata types. |
| 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. |
| route | Types and traits for routes and their request handlers and return types. |
| serde | Automatic serialization and deserialization support. |
| shield | Security and privacy headers for all outgoing responses. |
Macros
| catchers | |
| routes | |
| uri | Type-safe, encoding-safe route and non-route URI generation. |
Structs
| Catcher | An error catching route. |
| Config | Rocket server configuration. |
| Data | Type representing the body data of a request. |
| Error | An error that occurs during launch. |
| Request | The type of an incoming web request. |
| Response | A response, as returned by types implementing
|
| Rocket | The application server itself. |
| Route | A request handling route. |
| Shutdown | A request guard and future for graceful shutdown. |
| State | Request guard to retrieve managed state. |
Enums
| Build | The initial launch |
| Ignite | The second launch |
| Orbit | The final launch |
Traits
| Phase | A marker trait for Rocket’s launch phases. |
| Sentinel | An automatic last line of defense against launching an invalid |
Functions
| build | Creates a |
| custom | Creates a |
Attribute Macros
| async_test | Retrofits supports for |
| async_trait | Retrofits support for |
| catch | Attribute to generate a |
| delete | Attribute to generate a |
| get | Attribute to generate a |
| head | Attribute to generate a |
| launch | Generates a |
| main | Retrofits |
| options | Attribute to generate a |
| patch | Attribute to generate a |
| post | Attribute to generate a |
| put | Attribute to generate a |
| route | Attribute to generate a |
Derive Macros
| FromForm | Derive for the |
| FromFormField | Derive for the |
| Responder | Derive for the |
| UriDisplayPath | Derive for the |
| UriDisplayQuery | Derive for the |