1. @ardatan/sync-fetch
Synchronous version of the Fetch API
@ardatan/sync-fetch
Package: @ardatan/sync-fetch
Created by: larsgw
Last modified: Wed, 22 Jun 2022 14:19:11 GMT
Version: 0.0.1
License: MIT
Downloads: 9,765,007
Repository: https://github.com/larsgw/sync-fetch

Install

npm install @ardatan/sync-fetch
yarn add @ardatan/sync-fetch

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)

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin