Reputation: 65
I've the following code:
var request = require('request')
...
var options = {
method: 'post',
rejectUnauthorized: false,
url: '<my rest URI>',
headers: {
'content-type':json},
Authorization:'Basic',
auth: {
user: username,
password: password
}
}
...
request(options, function (err, res, body) {
if (err) {
console.dir(err);
retmessage= err;
res.render(err);
return;
}
console.dir('headers', res.headers)
console.dir('status code', res.statusCode)
console.dir(body)
})
I'm trying to invoke a REST API which needs json data payload. How do I add the payload to this call?
Upvotes: 0
Views: 1554
Reputation: 1591
put a body property in your options object. From https://github.com/request/request#requestoptions-callback:
body - entity body for PATCH, POST and PUT requests. Must be a Buffer or String, unless json is true. If json is true, then body must be a JSON-serializable object.
Upvotes: 1