在node.js express中构建多层restful API

在node.js express中构建多层restful API,node.js,rest,express,Node.js,Rest,Express,我正在使用node.js express构建简单的rest API,我已经构建了一个类似 app.get('/sites/:site/:building/:floor',function(req,res){ var building = req.params.building, floor = req.params.floor, site = req.params.site; console.log('query site ',site,building, floor);

我正在使用node.js express构建简单的rest API,我已经构建了一个类似

app.get('/sites/:site/:building/:floor',function(req,res){
    var building = req.params.building, floor = req.params.floor, site = req.params.site;
    console.log('query site ',site,building, floor);
    .....
}
客户端何时在angular.js中执行AJAX请求

$http.get('/sites/london')
         .success(function(data) {

        }).error(function(data, status, headers, config) {

        });
服务器不会响应这种URL,除非我将express API更改为

app.get('sites/:site',function(){})
app.get('sites/:site/:building',function(){})
app.get('sites/:site/:building/:floor',function(){}) 
但是上面的方法太单调了,所以我想知道是否可以用一句话来构建API
app.get('sites/:site/:building/:floor',function(){})
下面的内容应该可以帮到你。但是要回答你的问题,下面的方法应该可以

app.get('sites/:site?/:building?/:floor?',function(){})