I am a beginner with nodeJS.
What I am trying to do:
I have a POST API hosted and when I call it using postman, it gives me proper response as shown in image below:
But when I try to hit it using the NodeJS node-rest-client (https://www.npmjs.com/package/node-rest-client) it is giving me an irrelevant large object as below:
IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: true,
endEmitted: true,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
domain: null,
_events:
{ end: [ [Function: responseOnEnd], [Function] ],
data: [Function],
error: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
socket:
Socket {
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
I need help to get my proper object and I am not able to figure out what I am doing wrong here.
Below is my code to call REST API:
app.get('/notes', cors(), function(req, res) {
var args = {
"hiveMachineIp": "192.168.0.110",
"hiveMachinePort": "10000",
"hiveUsername": "nt",
"hivePassword": "",
"hiveDatabaseName": "default",
"hiveTableName": "transactions_24m",
"hiveAggregationColumn": "customerid",
"hiveAggregationFunction": "HISTOGRAM",
"hiveAggregationHistogramBin": "5"
};
var Client = require('node-rest-client').Client;
var client = new Client();
client.post("http://163.47.152.170:8090/MachinfinityDataPreparation/machinfinitydataprep/hiveDataAggregation/", args, function (data, response) {
// parsed response body as js object
// console.log(data);
// raw response
console.log(response);
});
// registering remote methods
client.registerMethod("postMethod", "http://163.47.152.170:8090/MachinfinityDataPreparation/machinfinitydataprep/hiveDataAggregation/", "POST");
client.methods.postMethod(args, function (data, response) {
// parsed response body as js object
// console.log(data);
// raw response
console.log(response);
});
})