0
votes

I am using a Restify server (node version is v9.11.1, restify version is 6.4.0).

Here is my server config :

server.use(restify.plugins.queryParser({  mapParams: true }))
server.use(restify.plugins.bodyParser({  mapParams: true }));
server.pre(restify.plugins.pre.userAgentConnection());
server.use(restify.plugins.acceptParser(server.acceptable));

server.pre(cors.preflight);
server.use(cors.actual);

Now, I want to test with a code sample, using Postman. I want to test query params and body params :

server.post('/ping/:param1', (req, res, next ) => {
console.log(req.params);
console.log(req.body);
res.send(200, { "ping" :true} );
return next() ;
});

My Postman configurations:

  • Content-Type as application/json
  • POST on url : http://127.0.0.1:8080/ping/value1 ( in order to test query parameters)
  • Body as "Raw" with content : { "hello" : "world" } ( to test body data)

After a POST query, I can get the query parameters, but I cant get the body data :

{ param1: 'value1' }
undefined
1
Try setting map params to false for the bodyParser. - HeadCode
It does not change anything when I set mapParams : false - Derek

1 Answers

1
votes

I just created a simple restify server with the server settings you listed above, with the exception of leaving out the cors stuff. I then hit the server using curl:

curl -F "hello=world" localhost:5555/ping/goodbye

and I got this on the server stdout:

{ param1: 'goodbye', hello: 'world' }
{ hello: 'world' }

I don't use Postman so I can't tell if it might not be working correctly for you, but this worked fine with curl.

My version info is as follows.

process.versions { http_parser: '2.7.0', node: '8.2.1', v8: '5.8.283.41', uv: '1.13.1', zlib: '1.2.11', ares: '1.10.1-DEV', modules: '57', openssl: '1.0.2l', icu: '59.1', unicode: '9.0', cldr: '31.0.1', tz: '2017b' }