the-fetch
Original Fetch API with some additional helpful feature
Feature
- Global onError callback function
- Global base URL
- Request & Response Intecpetors
Browser Support
Sorry ~ Only support the modern browsers
Installation
npm i the-fetch --save
Quick Start
fetchdefaultsbase = 'https://www.xxx.com/' // set base URL /** * If not set the response will resolve to json like * `fetch('').then(res => res.json())` * so in the example below you will see you can get json data only resolve once * If you want to resolve the res in another format you can pass the resolver in options like * `fetch('', { resolver: 'text' })` will resolve as `res.text()` * */fetch// or fetch// or
Interceptor
// Use request interceptor to change the initial configfetchinterceptorsrequest // Use response interceptor to do some extra work when request finishedfetchinterceptorsresponse