https://github.com/larsgw/sync-fetch
Synchronous wrapper around the Fetch API
https://github.com/larsgw/sync-fetch
Last synced: about 1 month ago
JSON representation
Synchronous wrapper around the Fetch API
- Host: GitHub
- URL: https://github.com/larsgw/sync-fetch
- Owner: larsgw
- License: mit
- Created: 2019-08-15T19:50:16.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-01-01T18:59:17.000Z (over 1 year ago)
- Last Synced: 2024-04-23T23:15:17.148Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 918 KB
- Stars: 34
- Watchers: 3
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sync-fetch
Synchronous wrapper around the Fetch API. Uses [`node-fetch`](https://github.com/bitinn/node-fetch) under the hood, and for some input-parsing code and test cases too.[](https://npmjs.com/package/sync-fetch)
[](https://npm-stat.com/charts.html?package=sync-fetch)## Install
npm install sync-fetch
In the browser, a browserify bundle can be loaded from CDNs like unpkg.com.
```html
```
## Use
```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()
// arrayBuffer(), blob(), buffer(), json(), and text() supported
```## Limitations
### Node.js
- Does not support `Stream` or `Blob` 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 on `SyncResponse` and `SyncRequest`### 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()` and `textConverted()` methods are not supported
- CORS limitations apply, of course (note they may be stricter for synchronous requests)