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