api-routes
Advanced tools
Comparing version
@@ -8,5 +8,7 @@ // Here we show how to do endpoint inheritance | ||
middleware: function (req, res, next) { req.tosay = 'my'; next() }, | ||
// You can put middleware here | ||
get: function (req, res) { | ||
res.send({method: 'get', endpoint: 'inheritance'}); | ||
res.send({method: 'get', endpoint: 'inheritance', tosay: req.tosay}); | ||
} | ||
@@ -22,5 +24,10 @@ }) | ||
middleware: [ | ||
function (req, res, next) { req.tosay = 'name'; next() }, | ||
function (req, res, next) { req.tosay += 'is'; next() } | ||
], | ||
// You can put middleware here | ||
get: function (req, res) { | ||
res.send({method: 'get', endpoint: 'inheritance.chain'}); | ||
res.send({method: 'get', endpoint: 'inheritance.chain', tosay: req.tosay}); | ||
} | ||
@@ -27,0 +34,0 @@ }) |
@@ -113,3 +113,8 @@ // api.js | ||
var url = (parent.url || '') + (child.url || ''); | ||
return _.extend(_.omit(parent, this.methods), child, {url: url}); | ||
return _.extend(_.omit(parent, this.methods), child, { | ||
url: url, | ||
middleware: parent.middleware && child.middleware ? | ||
[].concat(parent.middleware).concat(child.middleware) : | ||
child.middleware || parent.middleware | ||
}); | ||
}; | ||
@@ -116,0 +121,0 @@ |
{ | ||
"name": "api-routes", | ||
"description": "A declarative system for creating express API routes.", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"author": "Jon Eisen <jon.m.eisen@gmail.com>", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -45,5 +45,5 @@ var tests = module.exports = {}; | ||
tests.inheritance = makeTest('get', '/inheritance', {method:'get', endpoint: 'inheritance'}); | ||
tests.inheritance = makeTest('get', '/inheritance', {method:'get', endpoint: 'inheritance', tosay: 'my'}); | ||
tests.inheritanceChain = makeTest('get', '/inheritance/chain', { | ||
method:'get', endpoint:'inheritance.chain' | ||
method:'get', endpoint:'inheritance.chain', tosay: 'mynameis' | ||
}); | ||
@@ -50,0 +50,0 @@ |
15702
2.97%381
2.7%