@bigcommerce/request-sender

中文文档
1.3.0发布于 2026/10/07MITTypeScriptESM + CJS近 30 天下载 1.2万

HTTP request client for browsers

原始使用文档
文档目录10 节
  1. Usage
  2. API
  3. createRequestSender()
  4. createTimeout(delay: number?)
  5. RequestSender
  6. Timeout
  7. RequestOptions
  8. Response
  9. Development
  10. License

RequestSender

A simple library for sending HTTP requests.

Usage

To send a HTTP request.

import { createRequestSender } from '@bigcommerce/request-sender';

const requestSender = createRequestSender();

// GET request
requestSender.get('/foobars')
    .then(({ body }) => console.log(body));

// POST request
requestSender.post('/foobars', { body: { name: 'Foobar' } })
    .then(({ body }) => console.log(body));

To cancel a pending request

import { createRequestSender, createTimeout } from '@bigcommerce/request-sender';

const timeout = createTimeout(100);
const requestSender = createRequestSender();

requestSender.get('/foobars', { timeout })
    .catch(({ status }) => console.log(status));

timeout.cancel();

API

createRequestSender()

To create a new instance of RequestSender.

createTimeout(delay: number?)

To create a new instance of Timeout. If delay is defined, the instance will automatically timeout after the specified period. Otherwise, it remains inactive until complete() is called.

RequestSender

sendRequest(url: string, options: RequestOptions): Promise

get(url: string, options: RequestOptions): Promise

post(url: string, options: RequestOptions): Promise

put(url: string, options: RequestOptions): Promise

patch(url: string, options: RequestOptions): Promise

delete(url: string, options: RequestOptions): Promise

To submit a HTTP request using GET, POST, PUT, PATCH or DELETE method. Alternatively, you can call sendRequest and specify the request method as an argument.

Timeout

complete(): void;

To manually complete a timeout.

RequestOptions

body: any?

Request payload. Default: null

encodeParams: boolean?

URL encodes params. Default: true

headers: Object?

Request headers. Default: { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json', }

params: Object?

URL parameters. They get serialized as a query string. Default: null

method: string?

Request method. It's ignored if calling one of the convenience methods (get, post etc...). Default: GET

credentials: boolean?

Same as XMLHttpRequest.withCredentials. Default: true

timeout: Timeout?

Define if wish to timeout a request. Default: null

Response

body: any

Response body. Default: null

headers: Object

Response headers. Default: {}

status: number?

Response status code. Return 0 if the request is cancelled. Default: undefined

statusText: string?

Response status text. Default: undefined

Development

Some useful commands

# To test
npm test

# To lint
npm run lint

# To release
npm run release

For more commands, please see package.json

License

MIT

版本与发布记录

@bigcommerce/request-sender 共发布 25 个版本,首次发布于 2018/05/16;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.3.0latest2026/10/071 个月前
1.2.62025/05/211.5 年前
1.2.52025/05/021.5 年前
1.2.42024/03/212 年前
1.2.32024/03/052 年前
1.2.22024/01/172 年前

关于 @bigcommerce/request-sender 的常见问题

@bigcommerce/request-sender 是什么?

HTTP request client for browsers

如何安装 @bigcommerce/request-sender?

在项目目录运行 npm install @bigcommerce/request-sender,或使用 pnpm add / yarn add / bun add。

@bigcommerce/request-sender 支持 TypeScript 吗?

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

@bigcommerce/request-sender 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bigcommerce/request-sender 可以商用吗?

@bigcommerce/request-sender 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bigcommerce/request-sender 的下载量有多少?

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

@bigcommerce/request-sender 还在维护吗?

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