From 6bae33f0a67e0af2b364e05ca80cf91f340b7681 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 9 Feb 2024 17:07:55 +0100 Subject: [PATCH] chore: sample axum route --- Cargo.toml | 2 ++ src/main.rs | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6a0db62..a52bed7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +axum = "0.7.3" chrono = { version = "0.4.31", features = ["serde"] } serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" +tokio = { version = "1.35.1", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index d94b81c..ad40dbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,19 @@ pub mod model; -fn main() { - println!("Hello, world!"); +use axum::{ + routing::get, + Router, +}; + +#[tokio::main] +async fn main() { + // build our application with a single route + let app = Router::new().route("/", get(|| async { "Hello, World!" })); + + // 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(); }