38 lines
819 B
Rust
38 lines
819 B
Rust
#![feature(proc_macro_hygiene, decl_macro)]
|
|
|
|
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::http::RawStr;
|
|
|
|
#[get("/")]
|
|
fn index() -> &'static str {
|
|
"Hello, world!"
|
|
}
|
|
|
|
#[get("/hello/<name>")]
|
|
fn name(name: &RawStr) -> String {
|
|
format!("Hello, {}!", name.as_str())
|
|
}
|
|
|
|
#[get("/hello/<name>/<age>/<cool>")]
|
|
fn hello(name: String, age: u8, cool: bool) -> String {
|
|
if cool {
|
|
format!("You're a cool {} year old, {}!", age, name)
|
|
} else {
|
|
format!("{}, we need to talk about your coolness.", name)
|
|
}
|
|
}
|
|
|
|
#[get("/hello?wave&<name>")]
|
|
fn hello_query(name: Option<&RawStr>) -> String {
|
|
name.map(|name| format!("Hi, {}!", name))
|
|
.unwrap_or_else(|| "Hello!".into())
|
|
}
|
|
|
|
fn main() {
|
|
rocket::ignite()
|
|
.mount("/", routes![index, hello, hello_query, name])
|
|
.launch();
|
|
}
|
|
|