lazy-axios
v3.1.2
Published
Create wrapper for the axios. Uses to throttle frequent or repeated calls
Downloads
184
Readme
lazy-axios
Creates bunch of axios-throttled instances
Parameters
configs
Object dict of configs for axios-throttled
Examples
const LazyAxios = require('lazy-axios');;
const paths = {
from_string: {
query: 'https://yahoo.com/',
},
from_object: {
query: { url: 'https://google.com/' },
},
expand1: {
query: 'https://{host}/{path}',
},
expand2: {
query: 'https://[[host]]/[[path]]',
},
expand3: {
query: 'https://[[host]]/[[path]]',
placemarks: ['[[', ']]'],
},
till_3000: {
query: 'query: 'https://yahoo.com/',
}
};
const lazy_axios = new LazyAxios(paths);
// query url
const additionalParams = {params: {q: 'cats'}}
await lazy_axios.from_string.request(additionalParams);
// query as object
await lazy_axios['from_object'].request({params: {q: 'dogs'}});
// Using placeholders with default placemarks
await lazy_axios.expand1({host: 'mail.google.com', path: 'mail'}).request();
// Using placeholders and custom placemarks
await lazy_axios.expand2({host: 'mail.google.com', path: 'mail'}, ['[[', ']]']).request()
// Using placeholders and preseted custom placemarks
await lazy_axios.expand3({host: 'mail.google.com', path: 'mail'}).request()
// Block requests until year 3000
lazy_axios.till_3000.stay = () => Date.now() > (new Date('3000/01/01')).getTime()
await lazy_axios.till_3000({params: {q: 'jam'}}).request()