template api

This commit is contained in:
Mitchell Marino
2023-01-11 21:13:56 -06:00
parent 440a660e05
commit 5cd5cbce7c
3 changed files with 42 additions and 3 deletions
+21 -2
View File
@@ -1,3 +1,22 @@
fn main() {
println!("Hello, world!");
#[macro_use]
extern crate rocket;
use rocket::response::status::BadRequest;
#[get("/event")]
fn events() -> String {
format!("event list")
}
#[get("/event/<id>")]
fn event_id(id: Result<u64, &str>) -> Result<String, BadRequest<String>> {
match id {
Ok(id) => { Ok(format!("event for {}", id)) }
Err(_) => { Err(BadRequest(Some(format!("event id must be a valid u64")))) }
}
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![events, event_id])
}