Package Exports
- sync-fetch
- sync-fetch/browser.js
- sync-fetch/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sync-fetch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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.
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
orBlob
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 onSyncResponse
andSyncRequest
Browser
- Does not support most options, since
XMLHttpRequest
is pretty limited. Supported are:method
body
headers
credentials
(but notomit
)- (Non-spec)
timeout
- The non-standard
buffer()
andtextConverted()
methods are not supported - CORS limitations apply, of course (note they may be stricter for synchronous requests)