AxiosHttpClient
Hierarchy
- HttpClient
- AxiosHttpClient
Index
Constructors
constructor
Parameters
options: AxiosHttpClientOptions = {}
Returns AxiosHttpClient
Properties
axios
The axios instance the requests go through.
optionalhttpAgent
Keep-alive agent for plain HTTP, created with the first request in Node.js. It is the same ProxyAgent as
httpsAgent, so the socket pool is shared across both schemes.
readonlyinheritedhttpCompressor
Compressor the request pipeline runs the bodies worth compressing through.
optionalhttpsAgent
Keep-alive agent for HTTPS. The same instance as httpAgent.
inheritedlogger
Logger for the retry warnings.
inheritedmaxRetries
How many times a failed request is retried at most.
inheritedminDelayBetweenRetriesMillis
Lower bound for the delay before the first retry in milliseconds. It doubles with every further retry.
inheritedstats
Statistics of the API calls made through this client.
inheritedtimeoutMaxMillis
Upper bound for the timeout of a single attempt, in milliseconds.
inheritedtimeoutMillis
Duration of each timeout tier, in milliseconds.
Methods
inheritedcall
Makes an API request with automatic retries and exponential backoff.
Network errors the transport classifies as retryable, rate limits (HTTP 429) and server errors (HTTP 5xx) are retried up to maxRetries times. Any other error status is thrown as ApifyApiError right away. A request whose body is a
Readableis never retried, since part of the stream has already been consumed by the time the failure shows. Abortingconfig.signalends the attempt in flight, skips the remaining retries and rejects the call with the signal'sreason.Parameters
config: ApifyRequestConfig
The request to make.
Returns Promise<ApifyResponse<T>>
The successful response.
Throws - When the API responds with an error status the retries could not fix.
close
Destroys the keep-alive agents, closing every pooled socket. A client that never sent a request in Node.js has nothing to close.
Returns Promise<void>
isRetryableTransportError
A network failure is an axios error that carries the request it was sending: a connection that could not be made, dropped mid-way or timed out. Errors raised before a request exists, such as an invalid URL, are not retried.
Parameters
error: unknown
Returns boolean
isTimeoutError
A timeout is an axios error coded
ECONNABORTEDorETIMEDOUT, besides theTimeoutErrorthe base class recognizes.Parameters
error: unknown
Returns boolean
sendRequest
Sends the request through axios and hands the raw response back. A stream body is sent without following redirects, since the part of it already sent could not be replayed.
Parameters
request: HttpRequest
Returns Promise<HttpResponse>
inheritedsetDefaultAuthorization
Sets the
Authorizationheader from the token, unless an authorization header is already configured.Parameters
token: string
The Apify API token to send as the
Bearertoken.
Returns void
The default HTTP client of ApifyClient, built on axios.
It inherits the request pipeline from HttpClient and adds the transport: in Node.js, keep-alive agents that honor the
HTTP_PROXY,HTTPS_PROXYandNO_PROXYenvironment variables; in the browser, the XHR adapter of axios. Network errors are retried, timeouts included, and a stream body is sent without following redirects, since the part of it already sent could not be replayed.