request-many
v0.0.4
Published
Request with retries, max parallel requests options and delays
Downloads
5
Maintainers
Readme
request-many
Description
Request with retries, max parallel requests options and delays.
Installation
npm install request-many --save
Initialization
// Import.
const RequestMany = require('request-many');
Using
// Init with allowed 5 parallel requests.
const requestMany = new RequestMany(5);
// Do request. Set 2 retries count, 1000 milliseconds between retries and
// HTTP status codes list that should init retrying. Retries params not
// required and has default values.
const data = await requestMany.send({
url: 'https://example.com',
method: 'GET',
retries: {
httpStatusCodes: [500, 503],
count: 2,
waitMilliseconds: 1000
}
});
// Variable "data" equals { res, body } if correct or { error } with
// last retry error info. Body automatically parsed to object if can do
// it.
// Try to do 100 requests. Only 5 requests handled at one time, as
// initialized.
for (let i = 0; i < 100; i++) {
requestMany.send({
url: 'https://example.com',
method: 'GET',
retries: {
httpStatusCodes: [500, 503]
}
}).then(v => console.log(`${i} - ${v && v.body && v.body.length}`));
}
// Do request. Set 3 seconds delay before request.
const data = await requestMany.send({
url: 'https://example.com',
method: 'GET',
delayBefore: {
waitExactMilliseconds: 3000
}
});
// Do request. Set random delay before request in range from 1 to 5
// seconds.
const data = await requestMany.send({
url: 'https://example.com',
method: 'GET',
delayBefore: {
waitMinMilliseconds: 1000,
waitMaxMilliseconds: 5000
}
});
License
The MIT License (MIT)
Copyright © 2018 Volodymyr Sichka
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.