
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
bagofrequest
Advanced tools
Bag Of Request contains request utility functions.
bagofrequest#request
Send http request using mikeal/request, with the following additional features:
bagofrequest#proxy
Proxy retrieval based on URL and environment variables:
npm install bagofrequest
or as a dependency in package.json file:
"dependencies": {
"bagofrequest": "x.y.z"
}
var bag = require('bagofrequest');
Request:
// send http get request with query strings, timeout, and specified status code-based handlers
bag.request('get', 'http://somehost', {
queryStrings: {
param1: 'value1',
param2: 'value2'
},
timeout: 30000,
handlers: {
'2xx': function (result, cb) {
cb(null, result.somedata);
},
404: function (result, cb) {
cb(new Error('Item ' + result.itemId + ' cannot be found'));
}
}
},
function (err, result) {
// response with unexpected status code (no registered handler) will be passed as error
});
// send http post request
bag.request('post', 'http://somehost', {
headers: {
'content-type': 'application/json'
},
json: {
prop1: 'value1',
prop2: 'value2'
}
},
function (err, result) {
});
// send request with options to override any bagofrequest defaults (will be passed to mikeal/request)
bag.request('get', 'http://somehost', {
requestOpts: {
foo: 'bar'
}
},
function (err, result) {
});
// send request with retry settings
bag.request('get', 'http://somehost', {
retry: {
errorCodes: true, // retry on any error
statusCodes: [404, 503], // retry when response status code is 404 or 503
scale: 0.5, // increase delay by half on each retry
delay: 1000, // wait 1 second before retrying
maxRetries: 10 // only retry 10 times at most
}
},
function (err, result) {
});
// send request with custom proxy
bag.request('get', 'http://somehost', {
proxy: 'http://user:pass@someproxy:1234'
},
function (err, result) {
});
Proxy:
// get proxy based on URL protocol
// will return undefined when host is localhost or 127.0.0.1
var proxy = bag.proxy('https://somehost');
// get proxy with custom proxy exclusion
var proxy = bag.proxy('http://somelocalhost', {
noProxyHosts: ['somelocalhost']
});
Build reports:
1.0.0
FAQs
A bag-of-holding containing request utility functions.
The npm package bagofrequest receives a total of 141 weekly downloads. As such, bagofrequest popularity was classified as not popular.
We found that bagofrequest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.