# FetchHttpClient<!-- -->

The default HTTP client of [ApifyClient](https://docs.apify.com/api/client/js/reference/class/ApifyClient.md), built on the `fetch` of 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](https://docs.apify.com/api/client/js/reference/class/HttpClient.md) 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, `fetch` keeps connections alive on its own, and goes through a proxy only when Node.js is told to read the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables: start it with `NODE_USE_ENV_PROXY=1` (Node.js 22.21 and 24.0) or `--use-env-proxy` (Node.js 22.21 and 24.5).

### Hierarchy

* [HttpClient](https://docs.apify.com/api/client/js/reference/class/HttpClient.md)
  * *FetchHttpClient*

## Index[](#Index)

### Constructors

* [constructor](#constructor)

### Properties

* [httpCompressor](#httpCompressor)
* [logger](#logger)
* [maxRetries](#maxRetries)
* [minDelayBetweenRetriesMillis](#minDelayBetweenRetriesMillis)
* [stats](#stats)
* [timeoutMaxMillis](#timeoutMaxMillis)
* [timeoutMillis](#timeoutMillis)

### Methods

* [call](#call)
* [close](#close)
* [isRetryableTransportError](#isRetryableTransportError)
* [isTimeoutError](#isTimeoutError)
* [sendRequest](#sendRequest)
* [setDefaultAuthorization](#setDefaultAuthorization)

## Constructors<!-- -->[](#Constructors)

### [](#constructor)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/fetch.ts#L59)constructor

* **new FetchHttpClient**(options): [FetchHttpClient](https://docs.apify.com/api/client/js/reference/class/FetchHttpClient.md)

- Overrides HttpClient.constructor

  #### Parameters

  * ##### options: [FetchHttpClientOptions](https://docs.apify.com/api/client/js/reference/interface/FetchHttpClientOptions.md) = <!-- -->{}

  #### Returns [FetchHttpClient](https://docs.apify.com/api/client/js/reference/class/FetchHttpClient.md)

## Properties<!-- -->[](#Properties)

### [](#httpCompressor)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L362)readonlyinheritedhttpCompressor

httpCompressor: [HttpCompressor](https://docs.apify.com/api/client/js/reference/interface/HttpCompressor.md)

Inherited from HttpClient.httpCompressor

Compressor the request pipeline runs the bodies worth compressing through.

### [](#logger)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L347)inheritedlogger

logger: Log

Inherited from HttpClient.logger

Logger for the retry warnings.

### [](#maxRetries)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L350)inheritedmaxRetries

maxRetries: number

Inherited from HttpClient.maxRetries

How many times a failed request is retried at most.

### [](#minDelayBetweenRetriesMillis)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L353)inheritedminDelayBetweenRetriesMillis

minDelayBetweenRetriesMillis: number

Inherited from HttpClient.minDelayBetweenRetriesMillis

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

### [](#stats)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L344)inheritedstats

stats: Statistics

Inherited from HttpClient.stats

Statistics of the API calls made through this client.

### [](#timeoutMaxMillis)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L359)inheritedtimeoutMaxMillis

timeoutMaxMillis: number

Inherited from HttpClient.timeoutMaxMillis

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

### [](#timeoutMillis)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L356)inheritedtimeoutMillis

timeoutMillis: Record<[TimeoutTier](https://docs.apify.com/api/client/js/reference.md#TimeoutTier), number>

Inherited from HttpClient.timeoutMillis

Duration of each timeout tier, in milliseconds.

## Methods<!-- -->[](#Methods)

### [](#call)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L488)inheritedcall

* **call**\<T>(config): Promise<[ApifyResponse](https://docs.apify.com/api/client/js/reference/interface/ApifyResponse.md)\<T>>

- Inherited from HttpClient.call

  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.retryStatusCodes` picks other statuses to retry. Any other error status is thrown as [ApifyApiError](https://docs.apify.com/api/client/js/reference/class/ApifyApiError.md) right away, or returned when `config.throwOnErrorStatus` is `false`. A request whose body is a `Readable` or a web `ReadableStream` is never retried, since part of the stream has already been consumed by the time the failure shows. A `Blob` body 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 its `cause` when that error does not already wrap it. Aborting `config.signal` ends the attempt in flight, skips the remaining retries and rejects the call with the signal's `reason`.

  ***

  #### Parameters

  * ##### config: [ApifyRequestConfig](https://docs.apify.com/api/client/js/reference/interface/ApifyRequestConfig.md)

    The request to make.

  #### Returns Promise<[ApifyResponse](https://docs.apify.com/api/client/js/reference/interface/ApifyResponse.md)\<T>>

  The successful response, or the error response when `config.throwOnErrorStatus` is `false`.

  Throws - When the API responds with an error status the retries could not fix, unless `config.throwOnErrorStatus` is `false`.

### [](#close)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L447)inheritedclose

* **close**(): Promise\<void>

- Inherited from HttpClient.close

  Releases resources owned by the transport, such as a connection pool. The default does nothing.

  ***

  #### Returns Promise\<void>

### [](#isRetryableTransportError)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/fetch.ts#L79)isRetryableTransportError

* **isRetryableTransportError**(error): boolean

- Overrides HttpClient.isRetryableTransportError

  A network failure is the `TypeError` that `fetch` rejects with: a connection that could not be made, dropped mid-way or timed out. In Node.js it carries the failure as its `cause`, which tells it apart from a request that was never sent, such as one with an invalid URL. Bun rejects with an `Error` that has a `code` instead.

  ***

  #### Parameters

  * ##### error: unknown

  #### Returns boolean

### [](#isTimeoutError)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/fetch.ts#L68)isTimeoutError

* **isTimeoutError**(error): boolean

- Overrides HttpClient.isTimeoutError

  A timeout is the `TimeoutError` this client aborts a late request with, or a `fetch` failure caused by one of the connection, headers and body timeouts of Node.js.

  ***

  #### Parameters

  * ##### error: unknown

  #### Returns boolean

### [](#sendRequest)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/fetch.ts#L93)sendRequest

* **sendRequest**(request): Promise<[HttpResponse](https://docs.apify.com/api/client/js/reference/interface/HttpResponse.md)>

- Overrides HttpClient.sendRequest

  Sends the request through `fetch` and hands the raw response back. A stream body is sent without following redirects, and so is a request with `followRedirects: false`. A browser hides such a redirect response from the page, so there it fails the request.

  ***

  #### Parameters

  * ##### request: [HttpRequest](https://docs.apify.com/api/client/js/reference/interface/HttpRequest.md)

  #### Returns Promise<[HttpResponse](https://docs.apify.com/api/client/js/reference/interface/HttpResponse.md)>

### [](#setDefaultAuthorization)[](https://github.com/apify/apify-client-js/blob/84036425d1fb761bc98185b09045076b3c86192b/src/http_clients/base.ts#L415)inheritedsetDefaultAuthorization

* **setDefaultAuthorization**(token): void

- Inherited from HttpClient.setDefaultAuthorization

  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
