Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

meow

View respondTo.js
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.