public
Created

meow

  • Download Gist
respondTo.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 
var express = require('./')
, app = express();
 
var users = [];
 
users.push({ name: 'Tobi' });
users.push({ name: 'Loki' });
users.push({ name: 'Jane' });
 
app.get('/', function(req, res){
res.respondTo({
'text/html': function(){
res.send('<ul>' + users.map(function(user){
return '<li>' + user.name + '</li>';
}).join('') + '</ul>');
},
 
'text/plain': function(){
res.send(users.map(function(user){
return ' - ' + user.name + '\n';
}).join(''));
},
 
'application/json': function(){
res.json(users);
}
})
});
 
app.listen(3000);
console.log('listening on port 3000');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.