Node-restify: restify 5.0.0 bodyParser() not work

Created on 3 Jul 2017  路  9Comments  路  Source: restify/node-restify

Bug Report

I make a post request to restify server 5.0.0 . but cannot get body params in req.params

Restify Version

  • restify 5.0.0
  • node v8.0.0

Expected behaviour

with code blow:

const restify = require('restify');
const server = restify.createServer({
name: 'video-monitor-service',
version: '1.0.0'
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());

server.post('/scene/video/report', function(req, res, next){
console.log(req.params)
});

server.listen(3600, function() {
console.log('%s listening at %s', server.name, server.url);
});

and make curl post request as blow:

curl -X POST --data "data=xxx" http://localhost:3600/scene/video/report

I Expected get

{data:xxx}

Actual behaviour

I get req.parms an empty obj

{}

something wrong with my code? and is a bug with restify 5.0.0

Most helpful comment

It works, thank you @jgliner !

server.use(restify.plugins.queryParser({
    mapParams: true
}));
server.use(restify.plugins.bodyParser({
    mapParams: true
}));

All 9 comments

+1 It happens to me as well. Revert back to 4.3.1 for now.

+1 , got the same error
went back to 4.3.0

Looks like it's been deprecated...
https://github.com/restify/node-restify/blob/5.x/4TO5GUIDE.md

To re-enable, change server.use(restify.bodyParser()); to server.use(restify.plugins.bodyParser()); per this doc

They should draw more attention to this in their README.md. v5.0.0 breaks quite a few things.

It works, thank you @jgliner !

server.use(restify.plugins.queryParser({
    mapParams: true
}));
server.use(restify.plugins.bodyParser({
    mapParams: true
}));

It works, thank you @jgliner !

That's all it took. Thanks @jgliner!!

d0542c9ec210204c7c0126b614d01335c06f3ba345d1cb7f64 pimgpsh_thumbnail_win_distr

Change the NODE-PATH

image

@jgliner thanks. you save my time

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danhstevens picture danhstevens  路  6Comments

mongris picture mongris  路  5Comments

nodesocket picture nodesocket  路  4Comments

Sigurthorb picture Sigurthorb  路  4Comments

mikemilano picture mikemilano  路  4Comments