iota_rest_kv/routes/
health.rs

1// Copyright (c) 2025 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use axum::{Json, extract::State, response::IntoResponse};
5use serde::Serialize;
6
7use crate::types::SharedKvStoreClient;
8
9bin_version::bin_version!();
10
11/// Represent a health status response of the REST API server.
12#[derive(Serialize)]
13pub struct HealthResponse {
14    /// Version of the binary.
15    pub version: String,
16    /// The Git hash of the binary.
17    pub git_hash: String,
18    /// The total uptime of the REST API server.
19    pub uptime: String,
20    /// The status of REST API.
21    pub status: String,
22}
23
24/// Handles the health check request for the REST API server.
25///
26/// This endpoint provides information about the server's health, including
27/// the version, Git hash and uptime.
28pub async fn health(State(kv_store_client): State<SharedKvStoreClient>) -> impl IntoResponse {
29    let response = HealthResponse {
30        version: VERSION.to_owned(),
31        git_hash: GIT_REVISION.to_owned(),
32        uptime: format!("{:?}", kv_store_client.get_uptime()),
33        status: "OK".to_owned(),
34    };
35    Json(response)
36}