mirror of https://github.com/rwf2/Rocket.git
32 lines
821 B
Rust
32 lines
821 B
Rust
#![feature(plugin, decl_macro)]
|
|
#![plugin(rocket_codegen)]
|
|
|
|
extern crate rocket;
|
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
use rocket::response::content;
|
|
|
|
#[get("/hello/<name>/<age>")]
|
|
fn hello(name: String, age: i8) -> String {
|
|
format!("Hello, {} year old named {}!", age, name)
|
|
}
|
|
|
|
#[error(404)]
|
|
fn not_found(req: &rocket::Request) -> content::Html<String> {
|
|
content::Html(format!("<p>Sorry, but '{}' is not a valid path!</p>
|
|
<p>Try visiting /hello/<name>/<age> instead.</p>",
|
|
req.uri()))
|
|
}
|
|
|
|
fn main() {
|
|
let e = rocket::ignite()
|
|
// .mount("/", routes![hello, hello]) // uncoment this to get an error
|
|
.mount("/", routes![hello])
|
|
.catch(errors![not_found])
|
|
.launch();
|
|
|
|
println!("Whoops! Rocket didn't launch!");
|
|
println!("This went wrong: {}", e);
|
|
}
|