@bitfinex/bfx-facs-http

中文文档
1.1.3发布于 2026/08/21Apache-2.0CommonJS近 30 天下载 6753

比特芬克HTTP设施

中文使用文档
文档目录10 节
  1. 配置
  2. API 密码
  3. 请求
  4. fac.get (英语)
  5. 图片
  6. 直径.put
  7. 传真:fac.patch
  8. 传真
  9. 头部
  10. fac. 选项

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 - 服务器响应、承诺或回调结果

实例:

// 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 段落

回应:

  • 与请求方法相同

示例

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

图片

执行 HTTP POST 请求

参数 :

  • 与请求方法相同 method 段落

回应:

  • 与请求方法相同

示例

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 段落

回应:

  • 与请求方法相同

示例

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

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

传真:fac.patch

执行 HTTP PATCH 请求

参数 :

  • 与请求方法相同 method 段落

回应:

  • 与请求方法相同

示例

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

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

传真

执行 HTTP DELETE 请求

参数 :

  • 与请求方法相同 method 段落

回应:

  • 与请求方法相同

示例

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

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

头部

执行 HTTP 头部请求

参数 :

  • 与请求方法相同 method 段落

回应:

  • HTTP 响应头

示例

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 响应头

示例

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 共发布 5 个版本,首次发布于 2025/12/11;过去 12 个月发布了 5 个版本。

版本发布日期距今
1.1.3latest2026/08/212 个月前
1.1.22026/08/112 个月前
1.1.12026/07/243 个月前
1.1.02026/05/265 个月前
1.0.02025/12/1110 个月前

关于 @bitfinex/bfx-facs-http 的常见问题

@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 和提交记录判断。