@bitfinex/bfx-facs-http

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

Bitfinex HTTP Facility

原始使用文档
文档目录10 节
  1. Config
  2. API
  3. fac.request
  4. fac.get
  5. fac.post
  6. fac.put
  7. fac.patch
  8. fac.delete
  9. fac.head
  10. fac.options

bfx-facs-http

A facility that simplifies making http requests both on promise and callback approaches.

Config

Fac doesn't support config files but supports the options defined below:

  • baseUrl<String?> - Optional base url
  • timeout<Number?> - Optional request timeout, default one is node default timeout (0)
  • abortTimeout<Number?> - Optional abort timeout in ms, auto-creates an AbortController that aborts the request after the specified duration. Default is 0 (disabled). Per-request abortTimeout overrides this value. Ignored when caller provides their own signal
  • debug<(Boolean|Number)?> - Optional debug flag, default false
  • qs<(String|Array<String>|Object)?> - Optional, default query string params
  • dnsCaching<Boolean?> - Option dns caching, disabled by default

API

fac.request

Performs generic HTTP request

Params:

  • path<String> - Full request url or path
  • opts<Object?> - Optional request options
    • body<(String|Object)?> - Optional request body, in case of json encoding it can be also object
    • headers<Object<String, String>?> Optional request headers
    • method<String?> - Optional http method, currently supported get, head, post, put, patch, delete, options. Default value is get
    • redirect<Boolean?> - Optional, follow redirects or treat them as errors, default is treat as error
    • auth<Object?> - HTTP Basic authorization credentials. Overwrites header authorization. Please note only HTTP Basic auth is configurable through this parameter.
      • username<String?>
      • password<String?>
    • agent<http.Agent?> - Optional user agent
    • compress<Boolean?> - Optional, support gzip/deflate content encoding
    • timeout<Number?> - Optional request timeout, default is opt provided in fac setup (3s)
    • encoding<(String|Object)?> - Optional request and response encoding, if string is provided it applies to both request and response. Default encoding is text for both request and response
      • req<String?> - Optional request body encoding, supported: json and text. If no value is provided it will be treated as text
      • res<String?> - Optional response body encoding, supported: json, text and raw. If no value is provided it will be treated as text, if unsupported value is provided it will return buffer. If value is raw then body stream is returned, useful for file downloads
    • qs<(String|Array<String>|Object)?> - Optional, query string params
    • signal<AbortSignal?> - Optional, abort controller signal
    • abortTimeout<Number?> - Optional abort timeout in ms for this request, overrides facility-level abortTimeout. Ignored when signal is provided
    • dnsCaching<Boolean?> - Optional, enable dns caching
  • cb<Function?> - Optional callback function, if not provided call will be treated as promise

Response:

  • Promise<{ body: any, headers: object }>|void - Server response, promise or callback result

Examples:

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

Performs HTTP GET request

Params:

  • Same as in request method just without method param

Response:

  • Same as in request method

Example:

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

fac.post

Performs HTTP POST request

Params:

  • Same as in request method just without method param

Response:

  • Same as in request method

Example:

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)

fac.put

Performs HTTP PUT request

Params:

  • Same as in request method just without method param

Response:

  • Same as in request method

Example:

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

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

fac.patch

Performs HTTP PATCH request

Params:

  • Same as in request method just without method param

Response:

  • Same as in request method

Example:

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

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

fac.delete

Performs HTTP DELETE request

Params:

  • Same as in request method just without method param

Response:

  • Same as in request method

Example:

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

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

fac.head

Performs HTTP HEAD request

Params:

  • Same as in request method just without method param

Response:

  • HTTP response headers

Example:

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.options

Performs HTTP OPTIONS request

Params:

  • Same as in request method just without method param

Response:

  • HTTP response headers

Example:

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 是什么?

Bitfinex HTTP Facility

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