2016-04-06 10:26:43 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_macros)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
use rocket::Rocket;
|
|
|
|
|
|
|
|
#[route(GET, path = "/hello/<name>/<age>")]
|
|
|
|
fn hello(name: &str, age: i8) -> String {
|
|
|
|
format!("Hello, {} year old named {}!", age, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[error(code = "404")]
|
|
|
|
fn not_found() -> &'static str {
|
2016-04-06 20:50:02 +00:00
|
|
|
"<h1>Sorry pal.</h1><p>Go to '/hello/<name>/<age>' instead.</p>"
|
2016-04-06 10:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut rocket = Rocket::new("localhost", 8000);
|
|
|
|
rocket.mount("/", routes![hello]);
|
|
|
|
rocket.catch(errors![not_found]);
|
|
|
|
rocket.launch();
|
|
|
|
}
|