FetchHttpClient
Hierarchy
- HttpClient
- FetchHttpClient
Index
Constructors
constructor
Parameters
options: FetchHttpClientOptions = {}
Returns FetchHttpClient
Properties
readonlyinheritedhttpCompressor
Compressor the request pipeline runs the bodies worth compressing through.
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, and
config.retryStatusCodespicks other statuses to retry. Any other error status is thrown as ApifyApiError right away, or returned whenconfig.throwOnErrorStatusisfalse. A request whose body is aReadableor a webReadableStreamis never retried, since part of the stream has already been consumed by the time the failure shows. ABlobbody is read again for every attempt, so it is retried like any other, unless reading the blob itself fails: that error is thrown right away, with the transport error as itscausewhen that error does not already wrap it. 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, or the error response when
config.throwOnErrorStatusisfalse.Throws - When the API responds with an error status the retries could not fix, unless
config.throwOnErrorStatusisfalse.
inheritedclose
Releases resources owned by the transport, such as a connection pool. The default does nothing.
Returns Promise<void>
isRetryableTransportError
A network failure is the
TypeErrorthatfetchrejects with: a connection that could not be made, dropped mid-way or timed out. In Node.js it carries the failure as itscause, which tells it apart from a request that was never sent, such as one with an invalid URL. Bun rejects with anErrorthat has acodeinstead.Parameters
error: unknown
Returns boolean
isTimeoutError
A timeout is the
TimeoutErrorthis client aborts a late request with, or afetchfailure caused by one of the connection, headers and body timeouts of Node.js.Parameters
error: unknown
Returns boolean
sendRequest
Sends the request through
fetchand hands the raw response back. A stream body is sent without following redirects, and so is a request withfollowRedirects: false. A browser hides such a redirect response from the page, so there it fails the request.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 the
fetchof the runtime, so it works the same way in Node.js, browsers and edge runtimes and brings no dependency of its own.It inherits the request pipeline from HttpClient and adds the transport. 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. The timeout of a request runs until the response headers arrive and starts over with every chunk of the response body and of a stream body, so a large download or upload does not time out while it makes progress.
In Node.js,
fetchkeeps connections alive on its own, and goes through a proxy only when Node.js is told to read theHTTP_PROXY,HTTPS_PROXYandNO_PROXYenvironment variables: start it withNODE_USE_ENV_PROXY=1(Node.js 22.21 and 24.0) or--use-env-proxy(Node.js 22.21 and 24.5).