evanshortiss / fh-service-request

make requests to MBaaS Services using the regular request module API
0 stars 1 forks source link

Not able to get body parameters in fh service #2

Closed gaurav341 closed 7 years ago

gaurav341 commented 7 years ago

Basically i've a MBaaS service and a cloud app on RHMAP. I'm creating a post call from my cloud app to MBaaS service which is like

Cloud app code

`tasksMbaasRequest.post({
    uri: '/list',
    json: true,
    body: {
      id: 123456
    }
}, function(err, res, jsonData) {
    console.log(err, jsonData);
});`

MBaaS service code

`app.post('/list', function(req, res) {
    console.log(req.body); //getting req.body is {}
});`

Expected result {id: 123456}

evanshortiss commented 7 years ago

@gaurav341 I'm not sure what the issue is without more code to base it off of, but tasksMbaasRequest.post should be working. I've used this module to POST like so:

eventsHttp({
  method: 'POST',
  uri: '/events/ticket',
  timeout: 25000,
  json: {id: 12345}
}, callback);

My guess is you need to add the body-parser to your MBaaS route like so:

app.post('/list', require('body-parser').json(), function(req, res) {
    console.log(req.body); //getting req.body is {}
})

Let me know if this works for you.

evanshortiss commented 7 years ago

@gaurav341 I will assume this is working now. I can confirm it is working in projects we're developing.