A wrapper around reqwest to make working with Pocketbase a breeze
1use reqwest::{Method, header::HeaderMap};
2use serde::Deserialize;
3use serde_json::{Map, Value};
4
5use crate::{Error, PocketBase};
6
7#[derive(Clone, Debug)]
8/// Service that handles the Health APIs.
9pub struct HealthService<'a> {
10 /// Reference to the PocketBase client.
11 pub(super) client: &'a PocketBase,
12 /// Optional comma-separated list of fields to include in the response.
13 pub(super) fields: Option<String>,
14}
15
16#[derive(Clone, Debug, Deserialize)]
17pub struct HealthCheck {
18 /// Status message.
19 pub message: String,
20 /// Additional data.
21 pub data: Map<String, Value>,
22}
23
24impl HealthService<'_> {
25 /// Checks the health status of the api.
26 pub async fn check(self) -> Result<HealthCheck, Error> {
27 let mut params = Vec::new();
28 if let Some(fields) = self.fields {
29 params.push(("fields", fields));
30 }
31 self.client
32 .send(
33 "/api/health",
34 Method::GET,
35 HeaderMap::new(),
36 ¶ms,
37 None::<&()>,
38 )
39 .await
40 }
41}