Skip to content
Myr

Updated examples

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 75661a2 · Browse files · 4 files+15 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+15 added−13 removed

  • other:+15 added−13 removed

4 files+15 added−13 removed

modified:examples/blog/blog/index.js+3 added-2 removed
modified:examples/error/app.js+1 added-1 removed
modified:examples/github/app.js+2 added-2 removed
modified:examples/resource/app.js+9 added-8 removed
9 unmodified lines
10// Ad-hoc example resource method1112app.resource = function(path, obj) {13 this.get(path, obj.index);14 this.get(path + '/:a..:b', function(req, res, params){15 var a = parseInt(params.a, 10),16 b = parseInt(params.b, 10);14 this.get(path + '/:a..:b', function(req, res){15 var a = parseInt(req.params.a, 10),16 b = parseInt(req.params.b, 10);17 obj.range(req, res, a, b);18 });19 this.get(path + '/:id', obj.show);20 this.del(path + '/:id', obj.destroy);
15 unmodified lines
36var User = {37 index: function(req, res){38 res.send(users);39 },40 show: function(req, res, params){41 res.send(users[params.id] || { error: 'Cannot find user' });40 show: function(req, res){41 res.send(users[req.params.id] || { error: 'Cannot find user' });42 },43 destroy: function(req, res, params){44 var destroyed = params.id in users;45 delete users[params.id];43 destroy: function(req, res){44 var id = req.params.id;45 var destroyed = id in users;46 delete users[id];47 res.send(destroyed ? 'destroyed' : 'Cannot find user');48 },49 range: function(req, res, a, b){50 res.send(users.slice(a, b));
24 unmodified lines