# @dcl/fetch-component

> Fetch component for core components library

Latest version **1.1.2** (published 2026-08-14) · 0 weekly downloads

## Install

```sh
npm install @dcl/fetch-component
pnpm add @dcl/fetch-component
yarn add @dcl/fetch-component
bun add @dcl/fetch-component
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2026-08-14 |
| First published | 2026-06-02 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Maintainers | decentralandbot, imazzara |

## Links

- npm: https://www.npmjs.com/package/@dcl/fetch-component
- Repository: https://github.com/decentraland/core-components
- Homepage: https://github.com/decentraland/core-components#readme
- Issues: https://github.com/decentraland/core-components/issues
- npm.io page: https://npm.io/package/@dcl/fetch-component

## Dependencies (1)

- [@dcl/core-commons](https://npm.io/package/@dcl/core-commons.md) 0.11.0

## Recent versions

- 1.1.2 (latest) — 2026-08-14
- 1.1.1 — 2026-06-23
- 1.1.0 — 2026-06-22
- 1.0.1 — 2026-06-11
- 1.0.0 — 2026-06-02
- 0.0.1 — 2026-06-02

## README

# @dcl/fetch-component

Fetch component for core components library. It wraps the default Node `fetch`
API with retry, timeout and default-options support, and is meant to be used by
servers running on the default Node runtime.

## Installation

```bash
npm install @dcl/fetch-component
```

## Usage

```typescript
import { createFetchComponent } from '@dcl/fetch-component'

const fetcher = createFetchComponent({
  defaultHeaders: { 'X-Custom': 'value' }
})

const response = await fetcher.fetch('https://api.example.com/data', {
  method: 'GET',
  attempts: 3,
  retryDelay: 100,
  timeout: 5000
})

const data = await response.json()
```

## Features

- Backed by the default Node `fetch` API (no `cross-fetch`/`node-fetch` dependency)
- Automatic retries for idempotent requests (`GET`, `HEAD`, `OPTIONS`, `PUT`, `DELETE`)
- Retries both retryable status codes and network-level failures (DNS, connection refused/reset, socket hang up)
- Configurable retry delay and timeout per request
- Default headers and default request options shared across calls
- Type-safe through the shared `IFetchComponent` type from `@dcl/core-commons`

## Request options

In addition to the standard `RequestInit` options, `fetch` accepts:

- `attempts` - number of attempts for idempotent requests before giving up
- `retryDelay` - milliseconds to wait between retry attempts
- `timeout` - milliseconds to wait before aborting the request
- `abortController` - an `AbortController` used to abort the request

Non-retryable status codes (`400`, `401`, `403`, `404`) and non-idempotent
methods are never retried. Network-level failures (a rejected `fetch`) are
retried for idempotent methods up to `attempts` times; once the retries are
exhausted the last network error is re-thrown.

## License

Apache-2.0

---
_Source: https://npm.io/package/@dcl/fetch-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
