Created
November 14, 2014 05:41
-
-
Save anonymous/59b9d5c3e41658c63f70 to your computer and use it in GitHub Desktop.
middleware example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var o2x = require('object-to-xml'); | |
var j2c = require('json-2-csv'); | |
function(req, res, next) { | |
if(req.accepts('application/json')) { | |
return res.json(req.payload); | |
} | |
if(req.accepts('text/xml')) { | |
res.set('content-type', 'text/xml'); | |
return res.send(o2x(req.payload)); | |
} | |
if(req.accepts('text/csv')) { | |
req.set('content-type', 'text/csv'); | |
return res.send(j2c(req.payload)); | |
} | |
return res | |
.status(406) | |
.send('Not Acceptable'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment