request-defaults
v1.2.0
Published
Request wrapper for global defaults
Downloads
597
Readme
request-defaults
request wrapper for global defaults
request
provides .defaults()
method for setting default options, which returns new instance of request
with said defaults
in place. However, as these settings are not global, on every file where request is used, call to defaults()
with same options
is required. request-defaults
introduces globalDefaults()
method, which enables you to have these defaults set globally.
Install
$ npm install request-defaults
Usage
Instead of request
, use request-defaults
directly, which just provides instance of request
with said defaults in place.
var request = require('request-defaults');
request.globalDefaults()
Creates new instance of request
with given global defaults, which are used for every subsequent request-defaults
instance.
var request = require('request-defaults');
request.globalDefaults({
timeout: 10*1000
});
You can see the list of available defaults from request documentation.
Custom sets
You can also create custom sets as separate properties.
Note: Since globalDefaults()
creates new instance of request
so calling it will also clear any previously set custom properties.
var request = require('request-defaults');
request.api = request.defaults({
timeout: 20*1000
});
request.api.get('localhost/api/stuff', function(err, response, body) {
console.log('body');
});