Synchronous version of the Fetch API
npm install @ardatan/sync-fetchnode-fetch under the hood, and for some input-parsing code and test cases too.
npm install sync-fetch
``js
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
`
- Does not support Streams (or FormData) as input bodies since they cannot be read or serialized synchronouslyBlob
- Does not support s as input bodies since they're too complexagent
- Does not support the non-spec option as its value cannot be serialized
- Does not support most options, since XMLHttpRequest is pretty limited. Supported are:method
- body
- headers
- credentials
- (but not omit)timeout`
- (Non-spec)
- Does not support binary responses in the main thread
- CORS limitations apply, of course (note they may be stricter for synchronous requests)