Use the axum web framework to define a route that returns a 200 OK status with a JSON payload indicating the service is healthy.
use axum::{routing::get, Router};
async fn health_check() -> &'static str {
"OK"
}
#[tokio::main]
async fn main() {
let app = Router::new().route("/health", get(health_check));
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
Add axum = "0.7" and tokio = { version = "1", features = ["full"] } to your Cargo.toml.