Created
November 10, 2016 00:34
-
-
Save johntitus/e762d7f60d855999a31133fd52d30e0f to your computer and use it in GitHub Desktop.
How to use the Node.js Request module with defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request').defaults({ | |
headers: { | |
'X-header1': myvar, | |
'Content-Type': 'application/json' | |
} | |
}); | |
// Now request will automatically send the headers specified above on every request. | |
request.get('http://www.example.com', function(err, resp, body){ | |
//... | |
}); | |
// You can also do | |
var otherTypeOfDefaultRequest = require('request').defaults({ | |
headers: { | |
'Content-Type': 'text/xml' | |
} | |
}); | |
// Will automatically send the headers specified above. | |
otherTypeOfDefaultRequest.get('http://www.example.com', function(err, resp, body){ | |
//... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment