pub struct HttpTransport { /* private fields */ }Expand description
Shared HTTP transport handling auth, envelope parsing, and error mapping.
Implementations§
Source§impl HttpTransport
impl HttpTransport
pub fn new(base_url: impl Into<String>, api_key: impl Into<String>) -> Self
Sourcepub fn with_client(self, client: Client) -> Self
pub fn with_client(self, client: Client) -> Self
Use a custom reqwest::Client (e.g. with proxy or custom timeout).
pub fn client(&self) -> &Client
pub fn base_url(&self) -> &str
Sourcepub async fn request<T: DeserializeOwned>(
&self,
method: Method,
path: &str,
body: Option<&Value>,
) -> Result<T>
pub async fn request<T: DeserializeOwned>( &self, method: Method, path: &str, body: Option<&Value>, ) -> Result<T>
Send a JSON request and parse the envelope response.
Origin services return {"ok": true, "data": ...} on success
and {"ok": false, "error": ...} on failure.
Sourcepub async fn get<T: DeserializeOwned>(&self, path: &str) -> Result<T>
pub async fn get<T: DeserializeOwned>(&self, path: &str) -> Result<T>
GET convenience.
Sourcepub async fn post<T: DeserializeOwned>(
&self,
path: &str,
body: &Value,
) -> Result<T>
pub async fn post<T: DeserializeOwned>( &self, path: &str, body: &Value, ) -> Result<T>
POST convenience.
Sourcepub async fn delete<T: DeserializeOwned>(&self, path: &str) -> Result<T>
pub async fn delete<T: DeserializeOwned>(&self, path: &str) -> Result<T>
DELETE convenience.
Sourcepub async fn post_multipart<T: DeserializeOwned>(
&self,
path: &str,
form: Form,
) -> Result<T>
pub async fn post_multipart<T: DeserializeOwned>( &self, path: &str, form: Form, ) -> Result<T>
POST with multipart form data.
Trait Implementations§
Source§impl Clone for HttpTransport
impl Clone for HttpTransport
Source§fn clone(&self) -> HttpTransport
fn clone(&self) -> HttpTransport
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HttpTransport
impl !RefUnwindSafe for HttpTransport
impl Send for HttpTransport
impl Sync for HttpTransport
impl Unpin for HttpTransport
impl UnsafeUnpin for HttpTransport
impl !UnwindSafe for HttpTransport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more