Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

deser

Manav Rathib5a5455500fd
diff --git a/rust/core/examples/ping.rs b/rust/core/examples/ping.rs
index 0a5bf00047..9bcb6d630c 100644
--- a/rust/core/examples/ping.rs
+++ b/rust/core/examples/ping.rs
@@ -12,8 +12,8 @@ async fn main() {
let client = HttpClient::new(&base_url);
- match client.get("/ping").await {
- Ok(response) => println!("{}", response),
+ match client.ping().await {
+ Ok(response) => println!("message: {}, id: {}", response.message, response.id),
Err(e) => eprintln!("Error: {}", e),
}
}
diff --git a/rust/core/src/http.rs b/rust/core/src/http.rs
index d6e9fe899a..4ef15ec8a1 100644
--- a/rust/core/src/http.rs
+++ b/rust/core/src/http.rs
@@ -1,5 +1,6 @@
//! HTTP client for communicating with the Ente API.
+use serde::Deserialize;
use thiserror::Error;
/// HTTP client errors.
@@ -8,6 +9,19 @@ pub enum Error {
/// A network or HTTP protocol error occurred during the request.
#[error("HTTP request failed: {0}")]
Request(#[from] reqwest::Error),
+
+ /// Failed to parse JSON response.
+ #[error("JSON parse error: {0}")]
+ Json(#[from] serde_json::Error),
+}
+
+/// Response from the /ping endpoint
+#[derive(Deserialize, Debug)]
+pub struct PingResponse {
+ /// "pong"
+ pub message: String,
+ /// Git commit hash of the server.
+ pub id: String,
}
// TODO: Future HTTP features to implement:
@@ -40,6 +54,13 @@ impl HttpClient {
let text = response.text().await?;
Ok(text)
}
+
+ /// Ping the API, returns [PingResponse].
+ pub async fn ping(&self) -> Result<PingResponse, Error> {
+ let text = self.get("/ping").await?;
+ let response: PingResponse = serde_json::from_str(&text)?;
+ Ok(response)
+ }
}
#[cfg(test)]