Spring Boot-like health indicators.
#[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