axios-throttled

2.1.2 • Public • Published

axios-throttled

Creates throttling wrapper above axios

Parameters

  • config Object configs object
    • config.query (Object | String) axios query config (can be an url string)
    • config.stay Function? throttling stay function
    • config.logs Number? throttling logs parameter

requestRaw

Return axios query result

Parameters

  • config any additional config for query

Examples

const AxiosT = require('axios-throttled');;
 
const config = {
 query: 'https://google.com/'
};
 
const axiosT = new AxiosT(config);
await axiosT.requestRaw({params: {q: 'cats'}}); // return query result

Returns Promise

request

Return data key from axios query result

Parameters

  • config any additional config for query

Returns Promise

expandUrl

Fill url sketch with data

Parameters

  • params Object placeholders values (optional, default {})
  • placemarks Array.string? array with placemarks

Examples

const AxiosT = require('axios-throttled');;
 
const configs = {
 expand1: {
   query: 'https://{host}/{path}',
 },
 expand2: {
   query: 'https://[[host]]/[[path]]'
 },
 expand3: {
   query: 'https://[[host]]/[[path]]',
   placemarks: ['[[', ']]'],
 },
};
 
// Using default placemarks - `{` & `}`
const axiosT1 = new AxiosT(configs.expand1);
const mail1 = await axiosT1.expandUrl({domain: 'mail.google.com', path: 'mail'}).request();
 
// Using custom placemarks
const axiosT2 = new AxiosT(configs.expand2);
const mail2 = await axiosT2.expandUrl({domain: 'mail.google.com', path: 'mail'}, ['[[', ']]']).request();
 
// Using preseted custom placemarks
const axiosT3 = new AxiosT(configs.expand3);
const mail3 = await axiosT3.expandUrl({domain: 'mail.google.com', path: 'mail'}).request();

Returns any instance of this class

query

Returns Object

placemarks

Returns Array.string

throttling

getters & setters for axios throttling wrapper (stay, logs) can be used for additional configuration

Examples

const AxiosT = require('axios-throttled');;
 
const config = {
 query: 'https://yahoo.com/',
};
 
const axiosT = new AxiosT(config);
await axiosT.request({params: {q: 'dogs'}}); // will return query result
axiosT.stay = () => Date.now() > (new Date('3000/01/01')).getTime() // blocks requests until year 3000
await axiosT.request({params: {q: 'cats'}}); // will not invoke any request and return `undefined`

Readme

Keywords

Package Sidebar

Install

npm i axios-throttled

Weekly Downloads

30

Version

2.1.2

License

ISC

Unpacked Size

212 kB

Total Files

11

Last publish

Collaborators

  • a.chepugov