From 88b54b5a9c09b1959edb4b903684ac6bd94de55b Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 29 Mar 2025 15:42:30 -0400 Subject: [PATCH] Added web api code --- src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..530b52d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,39 @@ -fn main() { - println!("Hello, world!"); +use axum::{ + Json, Router, + http::StatusCode, + routing::{get, post}, +}; +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(get_full()).await.unwrap(); + axum::serve(listener, app).await.unwrap(); +} + +fn get_full() -> String { + get_address() + ":" + &get_port() +} +fn get_address() -> String { + String::from("0.0.0.0") +} + +fn get_port() -> String { + String::from("3000") +} + +// basic handler that responds with a static string +async fn root() -> &'static str { + "Hello, World!" }