mirror of https://github.com/rwf2/Rocket.git
24 lines
467 B
Rust
24 lines
467 B
Rust
#![feature(plugin, custom_derive)]
|
|
#![plugin(rocket_codegen)]
|
|
|
|
extern crate rocket;
|
|
|
|
#[derive(FromForm)]
|
|
struct Person<'r> {
|
|
name: &'r str,
|
|
age: Option<u8>
|
|
}
|
|
|
|
#[get("/hello?<person>")]
|
|
fn hello(person: Person) -> String {
|
|
if let Some(age) = person.age {
|
|
format!("Hello, {} year old named {}!", age, person.name)
|
|
} else {
|
|
format!("Hello {}!", person.name)
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
rocket::ignite().mount("/", routes![hello]).launch()
|
|
}
|