cortex_sdk/async_client/
core.rs1use super::transport::decode_value;
2use super::AsyncCortexDbClient;
3use crate::http::path;
4use crate::{
5 CellLookupResponse, HealthResponse, PutCellResponse, SdkResult, StatsResponse,
6 ValidationResponse, WriteBatchRequest, WriteBatchResponse,
7};
8
9impl AsyncCortexDbClient {
10 pub async fn health(&self) -> SdkResult<serde_json::Value> {
11 self.get("/v1/health").await
12 }
13
14 pub async fn health_response(&self) -> SdkResult<HealthResponse> {
15 decode_value(self.health().await?)
16 }
17
18 pub async fn stats(&self) -> SdkResult<serde_json::Value> {
19 self.get("/v1/stats").await
20 }
21
22 pub async fn stats_response(&self) -> SdkResult<StatsResponse> {
23 decode_value(self.stats().await?)
24 }
25
26 pub async fn validate(&self) -> SdkResult<serde_json::Value> {
27 self.get("/v1/validate").await
28 }
29
30 pub async fn validate_response(&self) -> SdkResult<ValidationResponse> {
31 decode_value(self.validate().await?)
32 }
33
34 pub async fn put_cell(&self, cell_id: u64, payload: &str) -> SdkResult<serde_json::Value> {
35 self.post(
36 &path("/v1/cell", &[("cell_id", &cell_id.to_string())]),
37 payload,
38 )
39 .await
40 }
41
42 pub async fn put_cell_response(
43 &self,
44 cell_id: u64,
45 payload: &str,
46 ) -> SdkResult<PutCellResponse> {
47 decode_value(self.put_cell(cell_id, payload).await?)
48 }
49
50 pub async fn write_batch(&self, request: &WriteBatchRequest) -> SdkResult<serde_json::Value> {
51 let body = serde_json::to_string(request)?;
52 self.post("/v1/batch", &body).await
53 }
54
55 pub async fn write_batch_response(
56 &self,
57 request: &WriteBatchRequest,
58 ) -> SdkResult<WriteBatchResponse> {
59 decode_value(self.write_batch(request).await?)
60 }
61
62 pub async fn get_cell(&self, cell_id: u64) -> SdkResult<serde_json::Value> {
63 self.get(&path("/v1/cell", &[("cell_id", &cell_id.to_string())]))
64 .await
65 }
66
67 pub async fn get_cell_response(&self, cell_id: u64) -> SdkResult<CellLookupResponse> {
68 decode_value(self.get_cell(cell_id).await?)
69 }
70
71 pub async fn tombstone_cell(&self, cell_id: u64) -> SdkResult<serde_json::Value> {
72 self.delete(&path("/v1/cell", &[("cell_id", &cell_id.to_string())]))
73 .await
74 }
75
76 pub async fn flush(&self) -> SdkResult<serde_json::Value> {
77 self.post("/v1/flush", "").await
78 }
79
80 pub async fn compact(&self) -> SdkResult<serde_json::Value> {
81 self.post("/v1/compact", "").await
82 }
83}