sync-fetch
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/sync-fetch package

0.5.2 • Public • Published

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

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()
// 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
  • The non-standard buffer() method is not supported
  • CORS limitations apply, of course (note they may be stricter for synchronous requests)

Readme

Keywords

Package Sidebar

Install

npm i sync-fetch

Weekly Downloads

600,719

Version

0.5.2

License

MIT

Unpacked Size

31.9 kB

Total Files

8

Last publish

Collaborators

  • larsgw