Create wrapper for the axios. Uses to throttle frequent or repeated calls
npm install lazy-axiosCreates bunch of [axios-throttled][1] instances
Parameters
- configs [Object][2] dict of configs for [axios-throttled][1]
##
Examples
``javascript
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()
``
[1]: https://www.npmjs.com/package/axios-throttled
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object