@bbc/http-transport

中文文档
5.0.1发布于 2026/10/14Apache-2.0TypeScriptCommonJS近 30 天下载 4259

A flexible, modular REST client built for ease-of-use and resilience.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Documentation
  4. TypeScript
  5. Opting Out
  6. Test

NPM downloads npm license github-issues stars forks

http-transport

A flexible, modular REST client built for ease-of-use and resilience

Installation

pnpm install @bbc/http-transport --save

Usage

const url = 'http://example.com/';
const client = require('@bbc/http-transport').createClient();

const res = await client
   .get(url)
   .asResponse();
  
  if (res.statusCode === 200) {
    console.log(res.body);
  }

Documentation

For more examples and API details, see API documentation

TypeScript

Types are included in this project, and they also work with plugins.

Just pass the types that your plugin will add to context as a generic. This will be overlayed on top of any types added by previous plugins in the chain.

E.g.

const addSessionData: Plugin<{ session: { userId: string } } }> = (context, next) => {
  context.session = { userId: 'some-user' };
};

const res = await client
  .use(addSessionData)
  .use((context, next) => {
    if (context.session.userId === 'some-user') { // this would error if addSessionData middleware was missing
      // do something
    }
  })
  .use<{res: { random: number } }>((context, next) => {
    context.res.random = Math.random();
  })
  .get(url)
  .asResponse();

console.log(res.random); // number

Opting Out

If you don't want to type your plugin, simply use any as the type. This is not recommended though as it means all plugins later in the chain will lose the types too, because they have no idea what changes were made.

const myPlugin: Plugin<any> = (context, next) => {};

Test

pnpm test

To generate a test coverage report:

pnpm run coverage

版本与发布记录

@bbc/http-transport 共发布 62 个版本,首次发布于 2017/09/05;过去 12 个月发布了 2 个版本。

版本发布日期距今
5.0.1latest2026/10/1424 天前
5.0.02026/10/1226 天前
4.6.22024/12/161.9 年前
4.6.12024/12/161.9 年前
4.6.02024/11/271.9 年前
4.5.12024/09/132 年前

其他发布通道:next → 3.5.7-0,node-fetch → 4.0.0-2。

关于 @bbc/http-transport 的常见问题

@bbc/http-transport 是什么?

A flexible, modular REST client built for ease-of-use and resilience.

如何安装 @bbc/http-transport?

在项目目录运行 npm install @bbc/http-transport,或使用 pnpm add / yarn add / bun add。

@bbc/http-transport 支持 TypeScript 吗?

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

@bbc/http-transport 支持 ESM 还是 CommonJS?

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

@bbc/http-transport 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bbc/http-transport 可以商用吗?

@bbc/http-transport 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bbc/http-transport 的下载量有多少?

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

@bbc/http-transport 还在维护吗?

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