From 991d5acf20ac8218b738dbbaa9418059f9be671f Mon Sep 17 00:00:00 2001 From: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:09:52 -0400 Subject: [PATCH] feat: add healthcheck api (#6) --- src/api.rs | 4 ++++ src/lib.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/api.rs b/src/api.rs index ff90376..a1db58c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -329,6 +329,10 @@ pub struct TypedQueryResponse { pub page_info: PageInfo, } +/// Healthcheck request for http api +#[derive(Serialize)] +pub struct HealthcheckRequest {} + #[cfg(test)] mod tests { use super::*; diff --git a/src/lib.rs b/src/lib.rs index f61704f..156c15c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,6 +66,11 @@ impl CeramicHttpClient { "/api/v0/admin/modelData" } + /// Get the healthcheck endpoint + pub fn healthcheck_endpoint(&self) -> &'static str { + "/api/v0/node/healthcheck" + } + /// Create a serde compatible request for model creation pub async fn create_model_request( &self, @@ -239,6 +244,11 @@ impl CeramicHttpClient { pagination, }) } + + /// Create a serde compatible request to check node health + pub async fn create_healthcheck_request(&self) -> anyhow::Result { + Ok(api::HealthcheckRequest {}) + } } /// Remote HTTP Functionality @@ -463,6 +473,20 @@ pub mod remote { page_info: resp.page_info, }) } + + /// Check Ceramic node health + pub async fn healthcheck(&self) -> anyhow::Result { + let req = self.cli.create_healthcheck_request().await?; + let resp = self + .remote + .get(self.url_for_path(self.cli.healthcheck_endpoint())?) + .json(&req) + .send() + .await? + .text() + .await?; + Ok(resp) + } } }