use polyte_core::RequestError;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::error::DataApiError;
#[derive(Clone)]
pub struct Health {
pub(crate) client: Client,
pub(crate) base_url: Url,
}
impl Health {
pub async fn check(&self) -> Result<HealthResponse, DataApiError> {
let response = self.client.get(self.base_url.clone()).send().await?;
let status = response.status();
if !status.is_success() {
return Err(DataApiError::from_response(response).await);
}
let health: HealthResponse = response.json().await?;
Ok(health)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthResponse {
pub data: String,
}