nido-svc-common 0.1.0-alpha.1

Shared health, error, OpenAPI, SSE, and middleware primitives for nido-*-svc crates
Documentation
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Generic `/health` handler for nido-*-svc crates.

use axum::{routing::get, Json, Router};
use serde_json::{json, Value};

/// Build a minimal router that serves `GET /health`.
///
/// Response: `{"ok": true, "name": "<service_name>", "version": "<version>"}`
pub fn health_router(service_name: &'static str, version: &'static str) -> Router {
    Router::new().route(
        "/health",
        get(move || health_handler(service_name, version)),
    )
}

pub async fn health_handler(service_name: &'static str, version: &'static str) -> Json<Value> {
    Json(json!({
        "ok": true,
        "name": service_name,
        "version": version,
    }))
}