pub struct HttpClient { /* private fields */ }Expand description
Internal HTTP client that handles requests with authentication and retries
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(config: ClientConfig) -> Result<Self, ApiError>
pub fn new(config: ClientConfig) -> Result<Self, ApiError>
Creates a new HttpClient, enabling OAuth automatically when the configuration provides an OAuth token endpoint together with client credentials.
Sourcepub fn new_with_oauth(
config: ClientConfig,
oauth_config: Option<OAuthConfig>,
) -> Result<Self, ApiError>
pub fn new_with_oauth( config: ClientConfig, oauth_config: Option<OAuthConfig>, ) -> Result<Self, ApiError>
Creates a new HttpClient with optional OAuth support.
When oauth_config is provided, the client will automatically fetch and refresh
OAuth tokens before making requests.
When config.reqwest_client is set, that client is used as-is and owns all
transport-level settings (TLS, proxies, timeout, user agent); SDK-level auth,
custom headers and retries are still applied on top of it.
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Returns a reference to the client configuration.
Sourcepub async fn execute_request_raw<T>(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<RawResponse<T>, ApiError>where
T: DeserializeOwned,
pub async fn execute_request_raw<T>(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<RawResponse<T>, ApiError>where
T: DeserializeOwned,
Execute a request and return the parsed body along with HTTP status code and headers.
Unlike execute_request, this method preserves the HTTP metadata from the response,
which is useful for paginated endpoints where callers need access to status codes
and headers alongside the deserialized body.
Sourcepub async fn execute_request<T>(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
pub async fn execute_request<T>(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
Execute a request with the given method, path, and options
Sourcepub async fn execute_request_with_base_url<T>(
&self,
base_url: &str,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
pub async fn execute_request_with_base_url<T>(
&self,
base_url: &str,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
Execute a request with an explicit base URL override.
Used for multi-URL environments where different endpoints resolve to different base URLs.
Sourcepub async fn execute_multipart_request<T>(
&self,
method: Method,
path: &str,
form: Form,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
pub async fn execute_multipart_request<T>(
&self,
method: Method,
path: &str,
form: Form,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
Execute a multipart/form-data request with the given method, path, and options
This method is used for file uploads using reqwest’s built-in multipart support.
Note: Multipart requests are not retried because they cannot be cloned.
RequestOptions::additional_body_params are not applied to multipart bodies.
§Example
let form = reqwest::multipart::Form::new()
.part("file", reqwest::multipart::Part::bytes(vec![1, 2, 3]));
let response: MyResponse = client.execute_multipart_request(
Method::POST,
"/upload",
form,
None,
None,
).await?;Sourcepub async fn execute_multipart_stream_request(
&self,
method: Method,
path: &str,
form: Form,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<ByteStream, ApiError>
pub async fn execute_multipart_stream_request( &self, method: Method, path: &str, form: Form, query_params: Option<Vec<(String, String)>>, options: Option<RequestOptions>, ) -> Result<ByteStream, ApiError>
Execute a multipart/form-data request and return a streaming response (ByteStream).
This method is used for file uploads that return binary data (e.g., audio conversion).
Note: Multipart requests are not retried because they cannot be cloned.
RequestOptions::additional_body_params are not applied to multipart bodies.
Sourcepub async fn execute_form_request<T>(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
pub async fn execute_form_request<T>(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<T, ApiError>where
T: DeserializeOwned,
Execute a request whose body is application/x-www-form-urlencoded.
The body is FORM-encoded, not JSON under a form label: .form() both serializes the
pairs and sets the header, where .json() would send a JSON document and stamp
application/json over the declared type. That is why this needs its own method rather
than the header override execute_request_with_content_type provides.
Sourcepub async fn execute_request_base64(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<Vec<u8>, ApiError>
pub async fn execute_request_base64( &self, method: Method, path: &str, body: Option<Value>, query_params: Option<Vec<(String, String)>>, options: Option<RequestOptions>, ) -> Result<Vec<u8>, ApiError>
Execute a request that returns a base64-encoded string and decode it to bytes
This method is used for endpoints that return raw base64-encoded data as a JSON string.
The response is expected to be a JSON string (e.g., "SGVsbG8gd29ybGQh") which is
decoded from base64 to raw bytes.
Sourcepub async fn execute_stream_request(
&self,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<ByteStream, ApiError>
pub async fn execute_stream_request( &self, method: Method, path: &str, body: Option<Value>, query_params: Option<Vec<(String, String)>>, options: Option<RequestOptions>, ) -> Result<ByteStream, ApiError>
Execute a request and return a streaming response (for large file downloads)
This method returns a ByteStream that can be used to download large files
efficiently without loading the entire content into memory. The stream can be
consumed chunk by chunk, written directly to disk, or collected into bytes.
§Examples
Option 1: Collect all bytes into memory
let stream = client.execute_stream_request(
Method::GET,
"/file",
None,
None,
None,
).await?;
let bytes = stream.collect().await?;Option 2: Process chunks with try_next()
let mut stream = client.execute_stream_request(
Method::GET,
"/large-file",
None,
None,
None,
).await?;
while let Some(chunk) = stream.try_next().await? {
process_chunk(&chunk);
}Option 3: Stream with futures::Stream trait
use futures::StreamExt;
let stream = client.execute_stream_request(
Method::GET,
"/large-file",
None,
None,
None,
).await?;
let mut file = tokio::fs::File::create("output.mp4").await?;
let mut stream = std::pin::pin!(stream);
while let Some(chunk) = stream.next().await {
let chunk = chunk?;
tokio::io::AsyncWriteExt::write_all(&mut file, &chunk).await?;
}Sourcepub async fn execute_stream_request_with_base_url(
&self,
base_url: &str,
method: Method,
path: &str,
body: Option<Value>,
query_params: Option<Vec<(String, String)>>,
options: Option<RequestOptions>,
) -> Result<ByteStream, ApiError>
pub async fn execute_stream_request_with_base_url( &self, base_url: &str, method: Method, path: &str, body: Option<Value>, query_params: Option<Vec<(String, String)>>, options: Option<RequestOptions>, ) -> Result<ByteStream, ApiError>
Execute a streaming request with an explicit base URL override.