我想使用快速扩展“基础”REST调用,但我认为我遇到了限制(或者我缺乏理解)。我希望所有REST端点共享相同的基本REST路由。我不想写这些为每个端点服务(即行星,恒星,等...)快速可变基础路由(REST)
app.get('/api/planet/type',function(req,res) {
...
});
app.get('/api/planet/type/:_id',function(req,res) {
...
});
app.post('/api/planet/type',function(req,res) {
...
});
app.patch('/api/planet/type/:_id',function(req,res){
...
});
app.delete('/api/planet/type/:_id',function(req,res) {
...
});
我宁愿做的是我实现模块中使用可变
require('base-rest')('/api/planet/type',planet-model);
require('base-rest')('/api/star/type',star-model);
然后使用一个变量作为基本端点,但它看起来像express可以在运行时处理动态路由。
app.get(baseURL,function(req,res) {
...
});
app.get(baseURL+'/:_id',function(req,res) {
...
});
这可能吗?如果是这样,我该如何做到这一点?
请注意,我用快递V4
所以我猜这是不可能的?任何人? – gpeters