I have a node.js application and I want to call a REST api by using http.request
. This is my code:
http = require("http");
const options = {
host: localhost,
port: 8103,
path: "/rest/getUser?userId=12345",
method: "GET"
};
http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
resolve(JSON.parse(chunk));
});
}).end();
The above code works fine, but I don't want to include the request parameter ?userId=12345
in the path. The path should be: /rest/getUser
. How do I set the request parameter with http.request
?