vinod vinod - 6 months ago 14
Node.js Question

Steps to send a https request to a rest service in Node js

What are the steps to send a https request in node js to a rest service?
I have an api exposed like https://133-70-97-54-43.sample.com/feedSample/Query_Status_View/Query_Status/Output1?STATUS=Joined%20school

How to pass the request and what are the options I need to give for this API like
host, port, path and method?

Answer

The easiest way is to use the request module.

request('https://example.com/url?a=b', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
});