Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ardatan/sync-fetch

larsgw9.7mMIT0.0.1

Synchronous version of the Fetch API

fetch, sync

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

Install

npm install sync-fetch

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()
// json(), arrayBuffer(), text() and buffer() supported

Limitations

Node.js

  • Does not support Streams (or FormData) as input bodies since they cannot be read or serialized synchronously
  • Does not support Blobs as input bodies since they're too complex
  • Does not support the non-spec agent option as its value cannot be serialized

Browser

  • Does not support most options, since XMLHttpRequest is pretty limited. Supported are:
    • method
    • body
    • headers
    • credentials (but not omit)
    • (Non-spec) timeout
  • Does not support binary responses in the main thread
  • CORS limitations apply, of course (note they may be stricter for synchronous requests)

changelog

0.4.1 (2022-05-26)

Bug Fixes

  • browser: re-add non-spec timeout option (168a46c)

0.4.0 (2022-05-26)

Bug Fixes

  • browser: improve browser compatibility (c65b3aa)
  • chore!: raise minimal Node.js version to 14 (096e7a3)

BREAKING CHANGES

  • Use Node.js 14 or higher. sync-fetch 0.3.x will keep getting critical security fixes if possible, but keep in mind that Node.js 12 itself is EOL and will itself not receive any security updates.

0.3.1 (2021-10-09)

Bug Fixes

  • transfer binary data correctly (674c848)

0.3.0 (2020-11-02)

  • chore!: drop node 8 and add 14 (b8b3e6c)

BREAKING CHANGES

  • drop Node 8 support

0.2.1 (2020-11-02)

Bug Fixes

  • call .join on stdin chunks array using empty string separator (bd609ad)

0.2.0 (2020-06-27)

  • refactor!: change class names (2e6a9ea)

BREAKING CHANGES

  • Changes Response and Request class names

0.1.1 (2019-10-24)

Bug Fixes

0.1.0 (2019-08-29)