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

View File

@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sqlx = { version = "0.6.2", features = ["postgres"] }
rocket = "0.5.0-rc.2"
sqlx = { version = "0.6", features = ["postgres", "runtime-tokio-rustls"] }
serde = "1.0"

18
docker-compose.yml Normal file
View File

@ -0,0 +1,18 @@
version: '3'
services:
school-app-db:
image: postgres
environment:
POSTGRES_DB: school_app_api
POSTGRES_PASSWORD: school_app_api_password
POSTGRES_USER: school_app_api_username
PGDATA: /db
volumes:
- ./pgdata:/db:rw
school-app-api:
image: school_app_api
depends_on: [school-app-db]
ports: ["4455:4455"]

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])
}