From 0822e02ca54b3c5fc4a7466377dc88bb69acfb3d Mon Sep 17 00:00:00 2001 From: bernard karaba Date: Thu, 25 Sep 2025 10:30:17 +0300 Subject: [PATCH] create health check route --- Cargo.lock | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +++ src/main.rs | 21 +++++++++++++++-- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1379af..d79a13d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -276,6 +276,9 @@ dependencies = [ "axum", "clippy", "rustfmt", + "serde", + "serde_json", + "tokio", ] [[package]] @@ -474,6 +477,16 @@ version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" +[[package]] +name = "lock_api" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" +dependencies = [ + "autocfg 1.5.0", + "scopeguard", +] + [[package]] name = "log" version = "0.3.9" @@ -551,6 +564,29 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "parking_lot" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.17", + "smallvec", + "windows-targets", +] + [[package]] name = "percent-encoding" version = "2.3.2" @@ -708,6 +744,15 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" +dependencies = [ + "bitflags 2.9.3", +] + [[package]] name = "redox_users" version = "0.3.5" @@ -715,7 +760,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ "getrandom", - "redox_syscall", + "redox_syscall 0.1.57", "rust-argon2", ] @@ -805,6 +850,12 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "semver" version = "0.9.0" @@ -874,6 +925,15 @@ dependencies = [ "serde", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.11" @@ -1000,10 +1060,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" dependencies = [ "backtrace", + "bytes", "io-uring", "libc", "mio", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "slab", "socket2", "tokio-macros", diff --git a/Cargo.toml b/Cargo.toml index 61b97f5..c3f2e40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ edition = "2024" [dependencies] axum = "0.7" +tokio = { version = "1.0", features = ["full"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" [dev-dependencies] clippy = "*" diff --git a/src/main.rs b/src/main.rs index e7a11a9..ed7bdb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,20 @@ -fn main() { - println!("Hello, world!"); +use axum::{ + routing::get, + Router, + Json, +}; +use serde_json::{json, Value}; + +#[tokio::main] +async fn main() { + let app = Router::new() + .route("/", get(|| async { "Hello, World!" })) + .route("/health", get(health_check)); + + let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + axum::serve(listener, app).await.unwrap(); +} + +async fn health_check() -> Json { + Json(json!({ "status": "ok" })) }