Struct rocket::Rocket
[−]
[src]
pub struct Rocket { /* fields omitted */ }
The main Rocket
type: used to mount routes and catchers and launch the
application.
Methods
impl Rocket
[src]
fn ignite() -> Rocket
Create a new Rocket
application using the configuration information in
Rocket.toml
. If the file does not exist or if there is an I/O error
reading the file, the defaults are used. See the
config documentation for more information
on defaults.
This method is typically called through the rocket::ignite
alias.
Panics
If there is an error parsing the Rocket.toml
file, this functions
prints a nice error message and then exits the process.
Examples
rocket::ignite()
fn custom(config: &Config) -> Rocket
Creates a new Rocket
application using the supplied custom
configuration information. Ignores the Rocket.toml
file. Does not
enable logging. To enable logging, use the hidden
logger::init(LoggingLevel)
method.
This method is typically called through the rocket::custom
alias.
Examples
use rocket::config::{Config, Environment}; let config = Config::default_for(Environment::active()?, "/custom")? .address("1.2.3.4".into()) .port(9234); let app = rocket::custom(&config);
fn mount(self, base: &str, routes: Vec<Route>) -> Self
Mounts all of the routes in the supplied vector at the given base
path. Mounting a route with path path
at path base
makes the route
available at base/path
.
Examples
Use the routes!
macro to mount routes created using the code
generation facilities. Requests to the /hello/world
URI will be
dispatched to the hi
route.
Panics
The base
mount point must be a static path. That is, the mount point
must not contain dynamic path parameters: <param>
.
#[get("/world")] fn hi() -> &'static str { "Hello!" } fn main() { rocket::ignite().mount("/hello", routes![hi]) }
Manually create a route named hi
at path "/world"
mounted at base
"/hello"
. Requests to the /hello/world
URI will be dispatched to the
hi
route.
use rocket::{Request, Route, Data}; use rocket::handler::Outcome; use rocket::http::Method::*; fn hi(_: &Request, _: Data) -> Outcome<'static> { Outcome::of("Hello!") } rocket::ignite().mount("/hello", vec![Route::new(Get, "/world", hi)])
fn catch(self, catchers: Vec<Catcher>) -> Self
Registers all of the catchers in the supplied vector.
Examples
#![feature(plugin)] #![plugin(rocket_codegen)] extern crate rocket; use rocket::Request; #[error(500)] fn internal_error() -> &'static str { "Whoops! Looks like we messed up." } #[error(400)] fn not_found(req: &Request) -> String { format!("I couldn't find '{}'. Try something else?", req.uri()) } fn main() { rocket::ignite().catch(errors![internal_error, not_found]) }