From 57ca0afdedb1c25f9f30ba016bcfbddd769119a1 Mon Sep 17 00:00:00 2001 From: KD Date: Sat, 29 Mar 2025 09:47:11 -0400 Subject: [PATCH] Added web api code --- src/main.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..4c1b3bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,28 @@ -fn main() { - println!("Hello, world!"); +use axum::{ + routing::{get, post}, + http::StatusCode, + Json, Router, +}; +use serde::{Deserialize, Serialize}; + +#[tokio::main] +async fn main() { + // initialize tracing + tracing_subscriber::fmt::init(); + + // build our application with a route + let app = Router::new() + // `GET /` goes to `root` + .route("/", get(root)); + // `POST /users` goes to `create_user` + // .route("/users", post(create_user)); + + // run our app with hyper, listening globally on port 3000 + let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + axum::serve(listener, app).await.unwrap(); +} + +// basic handler that responds with a static string +async fn root() -> &'static str { + "Hello, World!" }