2016-04-06 10:26:43 +00:00
|
|
|
#![feature(plugin)]
|
2016-09-09 03:38:58 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
2016-04-06 10:26:43 +00:00
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
2017-01-02 06:55:08 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
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-10-04 21:38:47 +00:00
|
|
|
fn not_found(req: &rocket::Request) -> 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-10-05 02:26:33 +00:00
|
|
|
req.uri())
|
2016-04-06 10:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2016-10-04 02:48:33 +00:00
|
|
|
rocket::ignite()
|
|
|
|
.mount("/", routes![hello])
|
|
|
|
.catch(errors![not_found])
|
|
|
|
.launch();
|
2016-04-06 10:26:43 +00:00
|
|
|
}
|