sync-fetch

Synchronous version of the Fetch API

MIT 19 个版本
安装
npm install sync-fetch
yarn add sync-fetch
pnpm add sync-fetch
bun add sync-fetch
README

sync-fetch

Synchronous wrapper around the Fetch API. Uses node-fetch under the hood, and for some input-parsing code and test cases too.

npm npm monthly downloads

Install

npm install sync-fetch

In the browser, a browserify bundle can be loaded from CDNs like unpkg.com.

<script src="https://unpkg.com/sync-fetch"></script>
<script src="https://unpkg.com/sync-fetch@VERSION"></script>

Use

const fetch = require('sync-fetch')

const metadata = fetch('https://doi.org/10.7717/peerj-cs.214', {
  headers: {
    Accept: 'application/vnd.citationstyles.csl+json'
  }
}).json()
// arrayBuffer(), blob(), buffer(), json(), and text() supported

Limitations

Node.js

  • Does not support Stream or Blob as input body since they cannot be read or serialized synchronously
  • Does not support FormData as input body yet as it has no built-in method to be serialized
  • Does not support the non-spec agent option as its value cannot be serialized
  • Does not support non-standard textConverted() method on SyncResponse and SyncRequest

Browser

  • Does not support most options, since XMLHttpRequest is pretty limited. Supported are:
    • method
    • body
    • headers
    • credentials (but not omit)
    • (Non-spec) timeout
  • The non-standard buffer() and textConverted() methods are not supported
  • CORS limitations apply, of course (note they may be stricter for synchronous requests)
版本列表
0.6.0-2 2024-11-20
0.6.0-1 2024-11-20
0.6.0-0 2024-11-19
0.6.0 2026-01-01
0.5.2 2023-06-11
0.5.1 2023-06-11
0.5.0 2023-06-11
0.4.5 2023-06-11
0.4.4 2023-06-11
0.4.3 2023-06-11
0.4.2 2022-09-24
0.4.1 2022-05-26
0.4.0 2022-05-26
0.3.1 2021-10-09
0.3.0 2020-11-02
0.2.1 2020-11-02
0.2.0 2020-06-27
0.1.1 2019-10-24
0.1.0 2019-08-29