Rocket/examples/query_params/src/main.rs

26 lines
500 B
Rust
Raw Normal View History

#![feature(plugin, decl_macro, custom_derive)]
2016-09-09 03:38:58 +00:00
#![plugin(rocket_codegen)]
extern crate rocket;
2016-12-29 03:29:12 +00:00
#[cfg(test)] mod tests;
#[derive(FromForm)]
struct Person {
name: String,
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();
}