pub struct ApiClient {
client: Client,
base_url: String,
api_key: Option<String>,
tenant_id: Option<String>,
}Expand description
Async HTTP client preconfigured with base URL and auth headers.
Fields§
§client: Client§base_url: String§api_key: Option<String>§tenant_id: Option<String>Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn new(
base_url: String,
api_key: Option<String>,
tenant_id: Option<String>,
) -> Self
pub fn new( base_url: String, api_key: Option<String>, tenant_id: Option<String>, ) -> Self
Create a new API client.
Resolution priority for base_url and api_key is handled by the caller (flag > env > session > default).
Sourcefn request(&self, method: Method, path: &str) -> RequestBuilder
fn request(&self, method: Method, path: &str) -> RequestBuilder
Build a request with common headers applied.
Sourcepub async fn get<T: DeserializeOwned>(&self, path: &str) -> Result<T>
pub async fn get<T: DeserializeOwned>(&self, path: &str) -> Result<T>
GET with typed deserialization.
Sourcepub async fn post<T: DeserializeOwned, B: Serialize>(
&self,
path: &str,
body: &B,
) -> Result<T>
pub async fn post<T: DeserializeOwned, B: Serialize>( &self, path: &str, body: &B, ) -> Result<T>
POST with typed request and response.
Sourcepub async fn post_raw<B: Serialize>(
&self,
path: &str,
body: &B,
) -> Result<Value>
pub async fn post_raw<B: Serialize>( &self, path: &str, body: &B, ) -> Result<Value>
POST returning raw JSON value.
Sourcepub async fn post_no_body<T: DeserializeOwned>(&self, path: &str) -> Result<T>
pub async fn post_no_body<T: DeserializeOwned>(&self, path: &str) -> Result<T>
POST with no request body, typed response.
Sourcepub async fn post_no_body_raw(&self, path: &str) -> Result<Value>
pub async fn post_no_body_raw(&self, path: &str) -> Result<Value>
POST with no request body, raw JSON response.
Auto Trait Implementations§
impl Freeze for ApiClient
impl !RefUnwindSafe for ApiClient
impl Send for ApiClient
impl Sync for ApiClient
impl Unpin for ApiClient
impl !UnwindSafe for ApiClient
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more