-
-
Save TyrfingMjolnir/db6c0dd8e0f318bb1935 to your computer and use it in GitHub Desktop.
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' ); | |
var j2t = require( 'json-2-tsv' ); | |
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 ) ); | |
} | |
if( req.accepts( 'text/tsv' ) ) { | |
req.set( 'content-type', 'text/tsv' ); | |
return res.send( j2t( req.payload ) ); | |
} | |
console.log( req.headers.accept ); | |
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