# @bitfinex/bfx-facs-http 中文文档

规范地址：https://npmcn.com/package/%40bitfinex/bfx-facs-http/

版本：1\.1\.3
npm 元数据更新时间：2026-08-21T07:45:42.178Z
中文译文更新时间：2026-11-08T04:18:57.022Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40bitfinex/bfx-facs-http
原文对照：https://npmcn.com/package/%40bitfinex/bfx-facs-http/?lang=original
项目主页：https://github.com/bitfinexcom/bfx-facs-http
源码仓库：https://github.com/bitfinexcom/bfx-facs-http

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：62.3 kB，9 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=16\.0
- 运行依赖：5 个
- 首次发布：2025-12-10T20:04:04.933Z
- 最新版本发布：2026-08-21T07:45:41.987Z
- 近 30 天下载量：6753（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 5 个）

## 中文简介

比特芬克HTTP设施

## 安装

```sh
npm install @bitfinex/bfx-facs-http
```

也可以使用：`pnpm add @bitfinex/bfx-facs-http`、`yarn add @bitfinex/bfx-facs-http`、`bun add @bitfinex/bfx-facs-http`

## README

# bfx-facs-http (英语)

简化了http对承诺和召回方法的要求.

## 配置

Fac 不支持配置文件,而是支持下面定义的选项:

-   `baseUrl<String?>` - 可选基础url
-   `timeout<Number?>` - 可选请求超时, 默认为节点默认超时( 0)
-   `abortTimeout<Number?>` - 在 ms 中可选中止超时, 自动创建一个中止控制器, 在指定的持续时间后中止请求 。 默认为 0( 损坏) 。 按请求 `abortTimeout` 覆盖此值。 当呼叫者自己提供时被忽略 `signal`
-   `debug<(Boolean|Number)?>` - 可选调试旗, 默认为假
-   `qs<(String|Array<String>|Object)?>` - 可选、默认的查询字符串参数
-   `dnsCaching<Boolean?>` - 默认禁用选项 dns 缓存

## API 密码

### 请求

执行通用 HTTP 请求

参数 :

-   `path<String>` - 完全请求url或路径
-   `opts<Object?>` - 可选请求选项
    -   `body<(String|Object)?>` - 可选请求体,如果Json编码,也可以是对象
    -   `headers<Object<String, String>?>` 可选请求头
    -   `method<String?>` - 目前支持的可选http方法 `get`, (中文(简体) ), `head`, (中文(简体) ), `post`, (中文(简体) ), `put`, (中文(简体) ), `patch`, (中文(简体) ), `delete`, (中文(简体) ), `options`默认值为 `get`
    -   `redirect<Boolean?>` - 可选,跟踪方向或视其为错误,默认则视其为错误
    -   `auth<Object?>` - HTTP基本授权证书。 覆盖信头 `authorization`。请注意 只有 HTTP Basic auth 通过此参数可配置 .
        -   `username<String?>`
        -   `password<String?>`
    -   `agent<http.Agent?>` - 可选用户代理
    -   `compress<Boolean?>` - 可选,支持gzip/deflate内容编码
    -   `timeout<Number?>` - 可选请求超时, 默认在 fac 设置( 3s) 中提供
    -   `encoding<(String|Object)?>` - 可选请求和答复编码, 如果字符串同时适用于请求和答复. 默认编码是请求和响应的文本
        -   `req<String?>` - 可选请求体编码,支持: `json` 财务报告和审定财务报表 `text`。 。 。 . 如果没有提供值,则将被视为文本
        -   `res<String?>` - 可选反应机体编码,支持: `json`, (中文(简体) ), `text` 财务报告和审定财务报表 `raw`。 。 。 . 如果没有提供价值,将被视为文字, 如果提供不支持的值,则返回缓冲. 如果值为 `raw` 然后返回正文流,用于文件下载
    -   `qs<(String|Array<String>|Object)?>` - 可选的查询字符串参数
    -   `signal<AbortSignal?>` - 可选的中止控制器信号
    -   `abortTimeout<Number?>` - 可选择的中止超时,以毫秒计,用于此请求,覆盖设施级别 `abortTimeout`。当 `signal` 提供
    -   `dnsCaching<Boolean?>` - 可选,允许 dns 缓存
-   `cb<Function?>` - 可选回调功能,如果不提供回调,将被视为承诺

回应:

-   `Promise<{ body: any, headers: object }>|void` - 服务器响应、承诺或回调结果

实例:

```js
// GET
const { body, headers } = await fac.request('https://example.com')

// POST
const { body, headers } = await fac.request('https://example.com/submit', { method: 'post', body: { foo: 'bar' }, encoding: 'json' })

// OPTIONS
const { headers } = await fac.request('https://api-pub.bitfinex.com/v2/conf/pub:list:currency', { method: 'options' })

// Callback
fac.request(
  '/data/store',
  { method: 'patch', body: 'test=33&foo=bar', headers: { 'content-type': 'application/x-www-form-urlencoded' } },
  (err, resp) => {
    ...
  })

// Request without options
fac.request('/data', (err, resp) => {
  ...
})

// error handling
fac.request('/data/store', (err) => {
  console.log(err.message) // ERR_HTTP: 500 - Internal Server Error
  console.log(err.status) // 500
  console.log(err.statusText) // Internal Server Error
  console.log(err.response) // { auth: 'failed' }
})

// file download
const stream = require('stream')

const { body: resp } = await fac.request('/file', { encoding: { res: 'raw' } }) // raw means return stream
await new Promise((resolve, reject) => {
  stream.pipeline(resp, fs.createWriteStream(writefile), (err) => err ? reject(err) : resolve())
})

// abort signal
const abortController = new AbortController()
setTimeout(() => {
  abortController.abort()
}, 1000)

const { body: resp } = await fac.request('/data', { signal: abortController.signal })

// abort timeout (auto-creates AbortController)
const { body: resp } = await fac.request('/data', { abortTimeout: 5000 })
```

### fac.get (英语)

执行 HTTP 获取请求

参数 :

-   与请求方法相同 `method` 段落

回应:

-   与请求方法相同

示例

```js
await fac.get('https://api-pub.bitfinex.com/v2/conf/pub:list:currency')
```

### 图片

执行 HTTP POST 请求

参数 :

-   与请求方法相同 `method` 段落

回应:

-   与请求方法相同

示例

```js
const FormData = require('form-data')

const form = new FormData();
form.append('a', 1);

const reqOpts = {
  body: form,
  headers: form.getHeaders()
}

await fac.post('/submit', reqOpts)
```

### 直径.put

执行 HTTP PUT 请求

参数 :

-   与请求方法相同 `method` 段落

回应:

-   与请求方法相同

示例

```js
const reqOpts = {
  body: JSON.stringify({ a: 1 }),
  headers: {
    'Content-Type': 'application/json'
  }
}

await fac.put('/data/store', reqOpts)
```

### 传真:fac.patch

执行 HTTP PATCH 请求

参数 :

-   与请求方法相同 `method` 段落

回应:

-   与请求方法相同

示例

```js
const reqOpts = {
  body: { a: 1 },
  encoding: 'json'
}

await fac.patch('/data/store', reqOpts)
```

### 传真

执行 HTTP DELETE 请求

参数 :

-   与请求方法相同 `method` 段落

回应:

-   与请求方法相同

示例

```js
const reqOpts = {
  body: JSON.stringify({ id: 31 }),
  headers: {
    'Content-Type': 'application/json'
  }
}

await fac.delete('/books', reqOpts)
```

### 头部

执行 HTTP 头部请求

参数 :

-   与请求方法相同 `method` 段落

回应:

-   HTTP 响应头

示例

```js
const { headers } = await fac.head('https://api-pub.bitfinex.com/v2/conf/pub:list:currency')
console.log(headers['content-type']) // 'application/json; charset=utf-8'
```

### fac. 选项

执行 HTTP 选项请求

参数 :

-   与请求方法相同 `method` 段落

回应:

-   HTTP 响应头

示例

```js
const { headers } = await fac.head('https://api-pub.bitfinex.com/v2/conf/pub:list:currency')
console.log(headers['allow']) // 'GET,PUT,POST'
```

## 常见问题

### @bitfinex/bfx-facs-http 是什么？

比特芬克HTTP设施

### 如何安装 @bitfinex/bfx-facs-http？

在项目目录运行 npm install @bitfinex/bfx-facs-http，或使用 pnpm add / yarn add / bun add。

### @bitfinex/bfx-facs-http 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/bitfinex\_\_bfx-facs-http 是否存在。

### @bitfinex/bfx-facs-http 支持 ESM 还是 CommonJS？

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

### @bitfinex/bfx-facs-http 需要什么版本的 Node\.js？

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

### @bitfinex/bfx-facs-http 可以商用吗？

@bitfinex/bfx-facs-http 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @bitfinex/bfx-facs-http 的下载量有多少？

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

### @bitfinex/bfx-facs-http 还在维护吗？

最新版本 1\.1\.3 发布于 2026/08/21（2 个月前）；至今共发布 5 个版本，其中过去 12 个月发布了 5 个；首次发布于 2025/12/11。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

