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 without OAuth support.
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.
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_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.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more