2.1.2 • Published 7 years ago

axios-throttled v2.1.2

Weekly downloads
56
License
ISC
Repository
github
Last release
7 years ago

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`
2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3-a

7 years ago

1.0.3

7 years ago

1.0.2-a

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago