快递中的路线参数数量可变吗?

Mat*_*tin 3 javascript rest node.js express ecmascript-6

cex.io的RESTful API的路由很有趣,其中可变数量的参数返回给定的所有货币对。

如何以快递方式实现?

这是我的意思的伪代码类型示例...

app.get('/pairs/:arg1/:arg2/:argn...', function(req, res, next) {
    // app logic
});
Run Code Online (Sandbox Code Playgroud)

小智 5

在快递中,您可以像*在路线中一样使用通配符,它还支持可以使用的Regex,这是如何实现此目的的示例

app.get('/pairs/*', function(req, res) {
   console.log(req.params[0]); 
});

// GET /pairs/testing/this/route
// Output: testing/this/route
Run Code Online (Sandbox Code Playgroud)

一旦有了,params就可以拆分,/从而在上面将分配给路由的所有参数组成一个数组。

有关快速路由的更多信息,请查看此页面