pub struct ApiClient<T: ApiInterface> { /* private fields */ }Expand description
The wrapper around an api definition that handles building and making requests correctly. Internally stores a copy of the current reqwest client, the global config, and the api interface to use. Can be safely sent across threads thanks to reqwest’s internal architecture. Note that interfaces impl Send + Sync by default as well.
Implementations§
Source§impl<T: ApiInterface> ApiClient<T>
impl<T: ApiInterface> ApiClient<T>
Sourcepub async fn request<R: DeserializeOwned, E: Display, HK: Into<HeaderName>, HV: Into<HeaderValue>, P: Serialize, B: Serialize>(
&self,
endpoint: E,
method: Method,
headers: HashMap<HK, HV>,
params: Option<P>,
body: Option<B>,
) -> Result<R>
pub async fn request<R: DeserializeOwned, E: Display, HK: Into<HeaderName>, HV: Into<HeaderValue>, P: Serialize, B: Serialize>( &self, endpoint: E, method: Method, headers: HashMap<HK, HV>, params: Option<P>, body: Option<B>, ) -> Result<R>
This member builds and executes a new request based on params passed in. It will call the underlying interface for the base api url and authentication methods, and collect all relevant info before executing. Return type is determined by the callee.
Sourcepub async fn string_request<E: Display, HK: Into<HeaderName>, HV: Into<HeaderValue>, P: Serialize, B: Serialize>(
&self,
endpoint: E,
method: Method,
headers: HashMap<HK, HV>,
params: Option<P>,
body: Option<B>,
) -> Result<String>
pub async fn string_request<E: Display, HK: Into<HeaderName>, HV: Into<HeaderValue>, P: Serialize, B: Serialize>( &self, endpoint: E, method: Method, headers: HashMap<HK, HV>, params: Option<P>, body: Option<B>, ) -> Result<String>
A debug version of Self::request that returns the body as text instead of deserializing
it. Useful if there is an issue with the call
Sourcepub async fn simple_get<R: DeserializeOwned, E: Display>(
&self,
endpoint: E,
) -> Result<R>
pub async fn simple_get<R: DeserializeOwned, E: Display>( &self, endpoint: E, ) -> Result<R>
A simple get method. Auto-sets specific params.
Sourcepub async fn get_params<R: DeserializeOwned, E: Display, P: Serialize>(
&self,
endpoint: E,
params: P,
) -> Result<R>
pub async fn get_params<R: DeserializeOwned, E: Display, P: Serialize>( &self, endpoint: E, params: P, ) -> Result<R>
A simple get method that allows also sending query params
Sourcepub async fn simple_post<R: DeserializeOwned, E: Display, B: Serialize>(
&self,
endpoint: E,
body: B,
) -> Result<R>
pub async fn simple_post<R: DeserializeOwned, E: Display, B: Serialize>( &self, endpoint: E, body: B, ) -> Result<R>
A simple post method that requires body
Sourcepub async fn post_params<R: DeserializeOwned, E: Display, P: Serialize, B: Serialize>(
&self,
endpoint: E,
params: P,
body: B,
) -> Result<R>
pub async fn post_params<R: DeserializeOwned, E: Display, P: Serialize, B: Serialize>( &self, endpoint: E, params: P, body: B, ) -> Result<R>
A simple post method that requires body and allows optional query params