Skip to main content

jax_daemon/http_server/health/
identity.rs

1use axum::extract::State;
2use axum::response::{IntoResponse, Response};
3use axum::Json;
4use http::StatusCode;
5use reqwest::{Client, RequestBuilder, Url};
6use serde::{Deserialize, Serialize};
7
8use crate::http_server::api::client::ApiRequest;
9use crate::ServiceState;
10
11/// Request type for the identity endpoint.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct IdentityRequest {}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct IdentityResponse {
17    /// The node's public identity (NodeId)
18    pub node_id: String,
19}
20
21impl ApiRequest for IdentityRequest {
22    type Response = IdentityResponse;
23
24    fn build_request(self, base_url: &Url, client: &Client) -> RequestBuilder {
25        let full_url = base_url.join("/_status/identity").unwrap();
26        client.get(full_url)
27    }
28}
29
30#[tracing::instrument(skip(state))]
31pub async fn handler(State(state): State<ServiceState>) -> Response {
32    let node_id = state.peer().id().to_string();
33    (StatusCode::OK, Json(IdentityResponse { node_id })).into_response()
34}