3 releases

new 0.1.2 Feb 18, 2025
0.1.1 Feb 17, 2025
0.1.0 Feb 17, 2025

#2128 in Database interfaces

47 downloads per month

MIT/Apache

37KB
328 lines

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

Dependencies

~5–19MB
~248K SLoC