mirror of https://github.com/rwf2/Rocket.git
25 lines
646 B
Rust
25 lines
646 B
Rust
#![feature(plugin)]
|
|
#![plugin(rocket_macros)]
|
|
|
|
extern crate rocket;
|
|
use rocket::{Rocket, Error, Request};
|
|
|
|
#[get("/hello/<name>/<age>")]
|
|
fn hello(name: &str, age: i8) -> String {
|
|
format!("Hello, {} year old named {}!", age, name)
|
|
}
|
|
|
|
#[error(404)]
|
|
fn not_found<'r>(_error: Error, request: &'r Request<'r>) -> String {
|
|
format!("<p>Sorry, but '{}' is not a valid path!</p>
|
|
<p>Try visiting /hello/<name>/<age> instead.</p>",
|
|
request.uri)
|
|
}
|
|
|
|
fn main() {
|
|
let mut rocket = Rocket::new("localhost", 8000);
|
|
rocket.mount("/", routes![hello]);
|
|
rocket.catch(errors![not_found]);
|
|
rocket.launch();
|
|
}
|