@dcl/fetch-component

中文文档
1.1.2发布于 2026/08/15TypeScriptCommonJS构建来源已验证近 30 天下载 7505

Fetch component for core components library

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Features
  4. Request options
  5. License

@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

npm install @dcl/fetch-component

Usage

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

版本与发布记录

@dcl/fetch-component 共发布 6 个版本,首次发布于 2026/06/02;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.2latest2026/08/152 个月前
1.1.12026/06/244 个月前
1.1.02026/06/224 个月前
1.0.12026/06/125 个月前
1.0.02026/06/025 个月前
0.0.12026/06/025 个月前

关于 @dcl/fetch-component 的常见问题

@dcl/fetch-component 是什么?

Fetch component for core components library

如何安装 @dcl/fetch-component?

在项目目录运行 npm install @dcl/fetch-component,或使用 pnpm add / yarn add / bun add。

@dcl/fetch-component 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dcl/fetch-component 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dcl/fetch-component 可以商用吗?

@dcl/fetch-component 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dcl/fetch-component 的下载量有多少?

根据 npm 官方下载统计,@dcl/fetch-component 在 2026/10/12 – 2026/11/10 这 30 天内被下载 7,505 次,日均约 250 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dcl/fetch-component 还在维护吗?

最新版本 1.1.2 发布于 2026/08/15(2 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/06/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。