npm i @hacknlove/fetchhelper
Polymorphic fetch helper that allows you to pass the parameters in many ways, and brings you the response conveniently processed for your REST APIs, with no dependences and less than 600 bytes.
Same as calling fetch(url, options)
Same as calling fetch(url, options)
Same as calling fetch(await promise, options)
Same as calling fetch(await promise)
Same as calling fetch(callfront(), options)
Same as calling fetch(callfront())
Same as calling fetch(await callfront(), options)
Same as calling fetch(await callfront())
It sets the body to JSON.stringify(options.json), and the Content-Type to application/json
It returns a promise that will resolve to [response, error]
, and never rejects
[null, error]
When
[null, {ok: false, .....}]
[await response.json(), udefined]
[null, json]
You can install the polyfill you want, or you can assign the fetch
you like to fetchHelper.fetch
import myFetchLibrary from 'myfetchlibrary'
import fetchHelper from '@hacknlove/fetchhelper'
fetchHelper.fetch
git clone https://github.com/hacknlove/fetchHelper.git
cd fetchHelper
npm install
npm test
I recomend to mock fetch
instead