Reputation: 2522
I see that the request
package is the standard for making HTTP API requests with NodeJS. I need to use it to send some requests but in the docs and all the examples I find, I don't see how to pass GET variables. I only see how to pass POST params. Here's my code:
request.get("https://api.example.com", function (err, res, body) {
if (!err) {
var resultsObj = JSON.parse(body);
//Just an example of how to access properties:
console.log(resultsObj.MRData);
}
});
Where to set the GET? I don't like doing it in the URL.
Upvotes: 0
Views: 572
Reputation: 416
You're looking for the qs
property. From the docs:
qs - object containing querystring values to be appended to the uri
request({
qs: {
foo: 'bar',
},
uri: 'http://foo.bar/'
}, callback)
Upvotes: 1