I'm new to Node/Restify and must be missing something stupid here, but I've been banging my head on this for awhile. Hopefully someone can help.
I'm trying to read Body parameters from a POST request with restify. Everything I find seems to suggest that all I need is server.user(bodyParser()), but its not working and I don't know why, and I'm not really sure how to troubleshoot further.
Can anyone help point me in the right direction on what I'm doing wrong here?
I created a simple server like follows:
var restify = require('restify');
var server = restify.createServer();
server.use(restify.bodyParser());
server.post("/test", function(req, res){
console.log(req.params);
console.log(req.body);
res.send(200);
res.end();
});
server.listen(8081);
I then ran the following POST request:
POST /test?GET_PARAM=def HTTP/1.1
Host: localhost:8081
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 33
POST_PARAM1=abc&POST_PARAM2=ghi
This results in the following in the console:
debugger listening on port 49953
{}
undefined
If I include queryParser, I can get the GET parameters without a problem, but what I really want is the post parameters either as straight standard params (like my example), or as JSON. I've tried the request both ways.
e.g. This gives the same response in the console:
POST /test?GET_PARAM=def HTTP/1.1
Host: localhost:8081
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 44
{ POST_PARAM1: 'abc', POST_PARAM2: 'ghi' }