Skip to content

Commit

Permalink
feat: add healthcheck api (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 authored Aug 28, 2023
1 parent b904924 commit 991d5ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ pub struct TypedQueryResponse<T> {
pub page_info: PageInfo,
}

/// Healthcheck request for http api
#[derive(Serialize)]
pub struct HealthcheckRequest {}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ impl<S: Signer> CeramicHttpClient<S> {
"/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,
Expand Down Expand Up @@ -239,6 +244,11 @@ impl<S: Signer> CeramicHttpClient<S> {
pagination,
})
}

/// Create a serde compatible request to check node health
pub async fn create_healthcheck_request(&self) -> anyhow::Result<api::HealthcheckRequest> {
Ok(api::HealthcheckRequest {})
}
}

/// Remote HTTP Functionality
Expand Down Expand Up @@ -463,6 +473,20 @@ pub mod remote {
page_info: resp.page_info,
})
}

/// Check Ceramic node health
pub async fn healthcheck(&self) -> anyhow::Result<String> {
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)
}
}
}

Expand Down

0 comments on commit 991d5ac

Please sign in to comment.