1.0.1 • Published 4 years ago
enhanced-fetch-lib v1.0.1
enhanced-fetch-lib
Cross browser wrapper for fetch.
Polyfill is used under the hood:
How to view example
Open /example/index.html
in your browser.
Before start
npm i
How to start project for development with example app
npm run development
, also you can use a production modenpm run build
- Open
/example/index.html
in your browser for test
How to build project for production
npm run build
For usage: you can use script tag, import or require
<script src="dist/index.js"></script>
if (!window['enhancedFetch']) {
alert('"enhancedFetch" is not defined in window scope');
return;
}
var { requestByFetch } = window['enhancedFetch'];
var fetchInstance = requestByFetch.createInstance({baseUrl: 'https://poller.jeetiss.now.sh',});
var abortC = fetchInstance.abortController();
fetchInstance.fetch('/post', {
signal: abortC.signal,
method: 'POST',
mode: "cors",
}, 10000,)
.then(res => res.json())
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
});
abortC.abort()
or
import enhancedFetch from 'enhanced-fetch-lib'
or
const enhancedFetch = require('enhanced-fetch-lib').default
or
const { enhancedFetch } = require('enhanced-fetch-lib')
TODO
- Add unit tests
- Improve example. Separate interface control from logic
- Publish into npm
- Add CI
- Add auto generation CHANGELOG and version - https://github.com/conventional-changelog/standard-version
- Add ESLint rules
- Add Prettier
- Add husky and lint-staged
- Add typings (TS or Flow)