Skip to main content
Version: Next

AxiosHttpClient

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_PROXY and NO_PROXY environment 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.

Hierarchy

Index

Constructors

constructor

Properties

axios

axios: AxiosInstance

The axios instance the requests go through.

optionalhttpAgent

httpAgent?: Agent

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

httpCompressor: HttpCompressor

Compressor the request pipeline runs the bodies worth compressing through.

optionalhttpsAgent

httpsAgent?: Agent

Keep-alive agent for HTTPS. The same instance as httpAgent.

inheritedlogger

logger: Log

Logger for the retry warnings.

inheritedmaxRetries

maxRetries: number

How many times a failed request is retried at most.

inheritedminDelayBetweenRetriesMillis

minDelayBetweenRetriesMillis: number

Lower bound for the delay before the first retry in milliseconds. It doubles with every further retry.

inheritedstats

stats: Statistics

Statistics of the API calls made through this client.

inheritedtimeoutMaxMillis

timeoutMaxMillis: number

Upper bound for the timeout of a single attempt, in milliseconds.

inheritedtimeoutMillis

timeoutMillis: Record<TimeoutTier, number>

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 Readable is never retried, since part of the stream has already been consumed by the time the failure shows. Aborting config.signal ends the attempt in flight, skips the remaining retries and rejects the call with the signal's reason.


    Parameters

    Returns Promise<ApifyResponse<T>>

    The successful response.

    Throws - When the API responds with an error status the retries could not fix.

close

  • close(): Promise<void>
  • 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

  • isRetryableTransportError(error): boolean
  • 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

  • isTimeoutError(error): boolean
  • A timeout is an axios error coded ECONNABORTED or ETIMEDOUT, besides the TimeoutError the 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

    Returns Promise<HttpResponse>

inheritedsetDefaultAuthorization

  • setDefaultAuthorization(token): void
  • Sets the Authorization header from the token, unless an authorization header is already configured.


    Parameters

    • token: string

      The Apify API token to send as the Bearer token.

    Returns void