An easy-to-host PDS on the ATProtocol, MacOS. Grandma-approved.

feat(identity-wallet): add relay HTTP client module

authored by malpercio.dev and committed by

Tangled e266e791 0906ab95

+47
+47
apps/identity-wallet/src-tauri/src/http.rs
··· 1 + //! Relay HTTP client for identity-wallet. 2 + //! 3 + //! All relay API calls go through `RelayClient`. The base URL is 4 + //! compile-time configured: `http://localhost:8080` in debug builds, 5 + //! `https://relay.ezpds.com` in release builds. 6 + 7 + // Suppressed until Phase 2 wires up the IPC command that calls this client. 8 + #![allow(dead_code)] 9 + 10 + use reqwest::{Client, Response}; 11 + use serde::Serialize; 12 + 13 + #[cfg(debug_assertions)] 14 + const RELAY_BASE_URL: &str = "http://localhost:8080"; 15 + #[cfg(not(debug_assertions))] 16 + const RELAY_BASE_URL: &str = "https://relay.ezpds.com"; 17 + 18 + /// HTTP client for relay API requests. 19 + pub struct RelayClient { 20 + client: Client, 21 + base_url: &'static str, 22 + } 23 + 24 + impl RelayClient { 25 + /// Create a new `RelayClient` with the compile-time base URL. 26 + pub fn new() -> Self { 27 + Self { 28 + client: Client::new(), 29 + base_url: RELAY_BASE_URL, 30 + } 31 + } 32 + 33 + /// POST JSON to `path` (relative, e.g. `"/v1/accounts/mobile"`). 34 + /// 35 + /// Returns the raw `Response` so callers can inspect the status code 36 + /// before attempting to deserialize the body. 37 + pub async fn post<T: Serialize>(&self, path: &str, body: &T) -> reqwest::Result<Response> { 38 + let url = format!("{}{}", self.base_url, path); 39 + self.client.post(&url).json(body).send().await 40 + } 41 + } 42 + 43 + impl Default for RelayClient { 44 + fn default() -> Self { 45 + Self::new() 46 + } 47 + }