axum-health

Crates.ioaxum-health
lib.rsaxum-health
version0.1.2
created_at2025-02-17 22:05:21.348284+00
updated_at2025-02-18 04:48:39.990932+00
descriptionSpring Boot like health indicators.
homepagehttps://github.com/alanbaumgartner/axum-health
repositoryhttps://github.com/alanbaumgartner/axum-health
max_upload_size
id1559381
size138,607
Alan Baumgartner (alanbaumgartner)

documentation

https://docs.rs/axum-health

README

axum-health

Spring Boot -like health indicators.

Usage

#[tokio::main]
async fn main() {
    let pool = SqlitePool::connect("test.db").await.unwrap();

    // Clone the pool!
    let indicator = DatabaseHealthIndicator::new("sqlite".to_owned(), pool.clone());

    let router = Router::new()
        .route("/health", get(axum_health::health))
        // Create a Health layer and add the indicator
        .layer(Health::builder().with_indicator(indicator).build())
        .with_state(pool);

    let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();

    axum::serve(listener, router.into_make_service())
        .await
        .unwrap()
}

The health endpoint will respond

{
  "status": "UP",
  "components": {
    "sqlite": {
      "status": "UP"
    }
  }
}

Checkout the examples

Commit count: 15

cargo fmt