request
request
Usage
import Request from '@swiftcarrot/request';
const req = new Request('https://api.example.com/v1').timeout(5000);
req.get('/articles', { page: 1 });
req
.post('/login', { name: 'test', password: '123' })
.then(({ token }) => req.token(token));
req.post('/articles', { title: 'test' });
req.delete('/logout').then(() => req.token(null));
onError
const request = new Request();
request.onError(err => {
console.warn(err);
});
add fetch Polyfill
// yarn add cross-fetch
import 'cross-fetch/polyfill';
License
MIT