If I use the barebones echo server demo for restify, it works correctly. But if I make a few changes shown below, it behaves different than I would expect:
var restify = require('restify');
function respond(req, res, next) {
res.send(req.params); //NOTE: should echo back all params
}
var server = restify.createServer();
server.get('/hello/', respond); //NOTE: parameter :name removed
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
What I've done is removed the name param from the URL and echoed all parameters in response function. calling:
http://localhost:8080/hello
returns
{}
but so does:
http://localhost:8080/hello?foo=bar
Why don't I see foo:bar in the response?
Everything that goes after the question mark in the URL are not params but query, and in order to reference it use: req.query.
Try this to echo back all data.
function respond(req, res, next) {
res.send({
params: req.params,
query: req.query
});
}
I found helpful answers in other post.
Ultimately I needed to add this for GETs
server.use(restify.queryParser());
and
server.use(restify.bodyParser());
for POSTs