Will
Will

Reputation: 1281

npm request set body

When using request, how do you set the request body? The form parameter creates a body of key value pairs: foo=bar&baz=qux, but how do you set the body to an arbitrary string?

Upvotes: 1

Views: 3124

Answers (1)

Neeraj Sharma
Neeraj Sharma

Reputation: 1105

You can set request body in the options params.

const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({test: 1});
};
request(options, function (err, res, body) {
  // handle err or use response and response boy
});

Depending upon the content you want to send, you can provide the string needed.

Upvotes: 2

Related Questions