pub struct HttpClient { /* private fields */ }Expand description
Low-level HTTP transport for the Apify API.
You usually do not interact with this directly — ApifyClient
owns an HttpClient and passes references to the resource clients.
Responsibilities:
- Base-URL + path concatenation.
- Bearer-token authentication.
- JSON body serialization / deserialization.
- Translating HTTP errors into
ApifyError. - Exponential-backoff retries for 429 Too Many Requests.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(token: Option<String>) -> Self
pub fn new(token: Option<String>) -> Self
Construct a new HTTP client.
token is optional — pass None for anonymous (read-only) access.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Override the base URL used for every request.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Re-build the underlying reqwest::Client with a custom timeout.
Sourcepub async fn request<T: DeserializeOwned>(
&self,
method: Method,
path: &str,
body: Option<impl Serialize>,
) -> Result<T, ApifyError>
pub async fn request<T: DeserializeOwned>( &self, method: Method, path: &str, body: Option<impl Serialize>, ) -> Result<T, ApifyError>
Send a request and deserialize the JSON body into T.
path is relative to the base URL (e.g. /actor-tasks).
Authentication and JSON Content-Type are handled automatically.
Sourcepub async fn request_with_retry<T: DeserializeOwned>(
&self,
method: Method,
path: &str,
body: Option<impl Serialize>,
) -> Result<T, ApifyError>
pub async fn request_with_retry<T: DeserializeOwned>( &self, method: Method, path: &str, body: Option<impl Serialize>, ) -> Result<T, ApifyError>
Send a request with exponential-backoff retries on 429 responses.
Starts with a 500 ms delay and doubles it up to 5 attempts. Use this for idempotent reads when you expect bursts of traffic.
Source§impl HttpClient
Convenience helpers that unwrap Apify’s { "data": ... } envelope.
impl HttpClient
Convenience helpers that unwrap Apify’s { "data": ... } envelope.
Sourcepub async fn get_data<T: DeserializeOwned>(
&self,
path: &str,
) -> Result<T, ApifyError>
pub async fn get_data<T: DeserializeOwned>( &self, path: &str, ) -> Result<T, ApifyError>
GET a single resource and return the inner data field.
Sourcepub async fn post_data<T: DeserializeOwned, B: Serialize>(
&self,
path: &str,
body: B,
) -> Result<T, ApifyError>
pub async fn post_data<T: DeserializeOwned, B: Serialize>( &self, path: &str, body: B, ) -> Result<T, ApifyError>
POST a JSON body and return the inner data field of the response.
Sourcepub async fn put_data<T: DeserializeOwned, B: Serialize>(
&self,
path: &str,
body: B,
) -> Result<T, ApifyError>
pub async fn put_data<T: DeserializeOwned, B: Serialize>( &self, path: &str, body: B, ) -> Result<T, ApifyError>
PUT a JSON body and return the inner data field of the response.
Sourcepub async fn delete_request(&self, path: &str) -> Result<(), ApifyError>
pub async fn delete_request(&self, path: &str) -> Result<(), ApifyError>
DELETE a resource, returning () on success.
Sourcepub async fn get_list<T: DeserializeOwned>(
&self,
path: &str,
) -> Result<ListData<T>, ApifyError>
pub async fn get_list<T: DeserializeOwned>( &self, path: &str, ) -> Result<ListData<T>, ApifyError>
GET a paginated list and return the inner ListData.