2017-08-29 03:14:59 +00:00
|
|
|
#![feature(plugin, decl_macro)]
|
2016-09-09 03:38:58 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
2016-04-06 10:26:43 +00:00
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
2017-01-31 10:43:19 +00:00
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
|
|
|
use rocket::response::content;
|
2017-01-02 06:55:08 +00:00
|
|
|
|
2016-09-04 08:05:17 +00:00
|
|
|
#[get("/hello/<name>/<age>")]
|
2017-03-31 07:18:58 +00:00
|
|
|
fn hello(name: String, age: i8) -> String {
|
2016-04-06 10:26:43 +00:00
|
|
|
format!("Hello, {} year old named {}!", age, name)
|
|
|
|
}
|
|
|
|
|
2016-09-04 08:05:17 +00:00
|
|
|
#[error(404)]
|
2017-07-12 22:21:45 +00:00
|
|
|
fn not_found(req: &rocket::Request) -> content::Html<String> {
|
|
|
|
content::Html(format!("<p>Sorry, but '{}' is not a valid path!</p>
|
2016-07-16 04:09:08 +00:00
|
|
|
<p>Try visiting /hello/<name>/<age> instead.</p>",
|
2017-01-31 10:43:19 +00:00
|
|
|
req.uri()))
|
2016-04-06 10:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2017-03-16 05:10:09 +00:00
|
|
|
let e = rocket::ignite()
|
2017-04-19 00:42:44 +00:00
|
|
|
// .mount("/", routes![hello, hello]) // uncoment this to get an error
|
2016-10-04 02:48:33 +00:00
|
|
|
.mount("/", routes![hello])
|
|
|
|
.catch(errors![not_found])
|
|
|
|
.launch();
|
2017-03-16 05:10:09 +00:00
|
|
|
|
|
|
|
println!("Whoops! Rocket didn't launch!");
|
|
|
|
println!("This went wrong: {}", e);
|
2016-04-06 10:26:43 +00:00
|
|
|
}
|