2016-04-06 10:26:43 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_macros)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
2016-07-16 04:09:08 +00:00
|
|
|
use rocket::{Rocket, RoutingError};
|
2016-04-06 10:26:43 +00:00
|
|
|
|
|
|
|
#[route(GET, path = "/hello/<name>/<age>")]
|
|
|
|
fn hello(name: &str, age: i8) -> String {
|
|
|
|
format!("Hello, {} year old named {}!", age, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[error(code = "404")]
|
2016-07-16 04:09:08 +00:00
|
|
|
fn not_found(error: RoutingError) -> String {
|
|
|
|
format!("<p>Sorry, but '{}' is not a valid path!</p>
|
|
|
|
<p>Try visiting /hello/<name>/<age> instead.</p>",
|
|
|
|
error.request.uri)
|
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();
|
|
|
|
}
|