wip: initial web server wiring

This commit is contained in:
Jeremy Wall 2025-03-29 20:32:25 -04:00
parent 394b0b5b77
commit 5dcbf57d15
4 changed files with 31 additions and 3 deletions

1
Cargo.lock generated
View File

@ -304,6 +304,7 @@ version = "0.1.0"
dependencies = [
"axum",
"serde",
"tokio",
]
[[package]]

View File

@ -3,6 +3,14 @@ name = "offline-web"
version = "0.1.0"
edition = "2021"
[lib]
path = "src/lib.rs"
[[bin]]
name = "example"
path = "src/main.rs"
[dependencies]
axum = "0.8.3"
serde = { version = "1.0.219", features = ["derive", "rc"] }
tokio = "1.44.1"

View File

@ -1,10 +1,24 @@
use std::rc::Rc;
use axum::{
routing::get,
Router
Router,
Json,
};
use datamodel::Reference;
mod datamodel;
pub fn endpoints() -> Router {
Router::new().route("/api/v1/ref/all/username", get(|| async { "hello world" }))
async fn all_references() -> Json<Rc<Reference>> {
Json(datamodel::Reference::new("silly id".to_string(), "all/username".to_string()).to_rc())
}
pub fn endpoints() -> Router {
Router::new().route("/api/v1/ref/all/username", get(all_references))
}
pub async fn serve() {
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap();
axum::serve(listener, endpoints()).await.unwrap();
}

5
src/main.rs Normal file
View File

@ -0,0 +1,5 @@
#[tokio::main(flavor = "current_thread")]
async fn main() {
offline_web::serve().await;
}