@chaos-kit/anfrage
v0.0.1
Published
> a lite library for fetch
Downloads
2
Readme
chaos-fetch
features
- [x] request-cache-controll (lru)
- [x] timeout
- [x] before/after hooks
- [x] async-pool
usage
- basic:
import { Anfrage, createAnfrage } from '@chaos-kit/anfrage';
// basic
let response1 = await Anfrage({
url: 'www.abc.com/abc/test'
});
// use createAnfrage
let instance = createAnfrage({
domain: 'www.abc.com'
});
let response2 = await instance.request({
url: '/abc/test',
method: 'GET',
})
// fast method
let response3 = await Anfrage.get('www.abc.com/test', {
// ...config
})
- cache controller
let instance = createAnfrage({
domain: 'www.abc.com',
cacheLimit: 20,
cacheTime: 500,
});
let data1 = instance.request({
url: '/abc/test',
method: 'GET'
});
let data2 = instance.request({
url: '/abc/test',
method: 'GET'
});
data1 === data2 // true
- abort request
let controller = new AbortController();
let signal = controller.signal;
let instance = createAnfrage({
domain: 'www.abc.com',
cacheLimit: 20,
cacheTime: 500,
});
let data1 = instance.request({
url: '/abc/test',
method: 'GET',
signal,
});
controller.abort(); // get AbortError()
- async-limit
let instance = createAnfrage({
domain: 'www.abc.com',
asyncLimit: 2,
});
let A = await instance.requet({
url: 'a'
})
let B = await instance.requet({
url: 'b'
})
let C = await instance.requet({
url: 'c'
})
// A, B will request immediatly, but C will be pending util A or B had finished