I'm not able to do url encoded posts to my node.js API using restify. I have the following setup of my restify app:
app.use(restify.acceptParser(app.acceptable));
app.use(restify.queryParser());
app.use(restify.urlEncodedBodyParser());
But when I'm requesting my app using curl with the following request:
curl -X POST -H "Content-type: application/x-www-form-urlencoded" -d quantity=50 http://app:5000/feeds
I get the following input body in my view:
console.log(req.body) // "quantity=50"
Thanks in advance,
Mattias
The default setup for Restify places parsed parameters in req.params
. This is done by both the queryParser
and the different bodyParser
middlewares.
So to access the quantity
parameter, use req.params.quantity
.
If you really want to use req.body
instead, you need to pass mapParams : false
to the bodyParser
constructor:
app.use(restify.plugins.urlEncodedBodyParser({ mapParams : false }));
Now req.body
will contain the parsed parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With