I'm trying to use a formatter with Restify in NodeJS. This is the code:
var restify = require('restify')
var utils = require('util')
function f1(req, res, next) {
res.json({
number: 1,
name: 'John',
gender: 'male'
});
next()
}
var server = restify.createServer({
formatters: {
'application/bash': function f2(req, res, body) {
var ret = "";
console.log("Hi, I'm in the formatters ")
for(var propertyName in body) {
ret += utils.format("%s=%s ", propertyName, body[propertyName]);
}
return ret.trim();
}
}
});
server.get('/', f1);
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
if I make a GET request setting Content-Type to application/bash, i get the json object instead of something like "key=value key=value..." and a content type setted to application/json. Also i didn't see the console.log(). How can i fix it? Where is the bug?