Skip to content

Commit 991d5ac

Browse files
authored
feat: add healthcheck api (#6)
1 parent b904924 commit 991d5ac

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ pub struct TypedQueryResponse<T> {
329329
pub page_info: PageInfo,
330330
}
331331

332+
/// Healthcheck request for http api
333+
#[derive(Serialize)]
334+
pub struct HealthcheckRequest {}
335+
332336
#[cfg(test)]
333337
mod tests {
334338
use super::*;

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ impl<S: Signer> CeramicHttpClient<S> {
6666
"/api/v0/admin/modelData"
6767
}
6868

69+
/// Get the healthcheck endpoint
70+
pub fn healthcheck_endpoint(&self) -> &'static str {
71+
"/api/v0/node/healthcheck"
72+
}
73+
6974
/// Create a serde compatible request for model creation
7075
pub async fn create_model_request(
7176
&self,
@@ -239,6 +244,11 @@ impl<S: Signer> CeramicHttpClient<S> {
239244
pagination,
240245
})
241246
}
247+
248+
/// Create a serde compatible request to check node health
249+
pub async fn create_healthcheck_request(&self) -> anyhow::Result<api::HealthcheckRequest> {
250+
Ok(api::HealthcheckRequest {})
251+
}
242252
}
243253

244254
/// Remote HTTP Functionality
@@ -463,6 +473,20 @@ pub mod remote {
463473
page_info: resp.page_info,
464474
})
465475
}
476+
477+
/// Check Ceramic node health
478+
pub async fn healthcheck(&self) -> anyhow::Result<String> {
479+
let req = self.cli.create_healthcheck_request().await?;
480+
let resp = self
481+
.remote
482+
.get(self.url_for_path(self.cli.healthcheck_endpoint())?)
483+
.json(&req)
484+
.send()
485+
.await?
486+
.text()
487+
.await?;
488+
Ok(resp)
489+
}
466490
}
467491
}
468492

0 commit comments

Comments
 (0)