2019-06-20 06:03:21 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2016-04-06 10:26:43 +00:00
|
|
|
|
2018-06-28 15:55:15 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2016-04-06 10:26:43 +00:00
|
|
|
|
2017-01-31 10:43:19 +00:00
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
2018-09-17 03:52:07 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:04:14 +00:00
|
|
|
#[catch(404)]
|
2019-06-13 02:41:29 +00:00
|
|
|
fn not_found(req: &rocket::Request<'_>) -> content::Html<String> {
|
2017-07-12 22:21:45 +00:00
|
|
|
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])
|
2018-09-16 08:47:51 +00:00
|
|
|
.register(catchers![not_found])
|
2016-10-04 02:48:33 +00:00
|
|
|
.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
|
|
|
}
|