#![feature(proc_macro_hygiene)] #[macro_use] extern crate rocket; #[cfg(test)] mod tests; use rocket::request::{Form, LenientForm}; #[derive(FromForm)] struct Person { /// Use the `form` attribute to expect an invalid Rust identifier in the HTTP form. #[form(field = "first-name")] name: String, age: Option } #[get("/hello?")] fn hello(person: Option>) -> String { if let Some(person) = person { if let Some(age) = person.age { format!("Hello, {} year old named {}!", age, person.name) } else { format!("Hello {}!", person.name) } } else { "We're gonna need a name, and only a name.".into() } } #[get("/hello?age=20&")] fn hello_20(person: LenientForm) -> String { format!("20 years old? Hi, {}!", person.name) } fn rocket() -> rocket::Rocket { rocket::ignite().mount("/", routes![hello, hello_20]) } fn main() { rocket().launch(); }