VERTX中的可选路径参数
我想使用get请求将单个端点中的可选路径参数获取。例如: -
如果用户点击API以下: -
- /Metric/Monitor/:ID 或者 /metric/:ID
此处的ID是路径参数,而不是我需要使用Get Request在单个终点中路由到同一函数。我该怎么做?
I want to use a get request to get optional path parameters in a single end point . For example :-
if user hit below api :-
- /metric/monitor/:id
or
/metric/:id
here id is path parameter than i need to route to the same function in a single end point using get request. How can i do the same ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用正则表达式指定路由。
假设ID是一个数字:
然后读取值:
这是我通常使用Vert.x Web 4.3.1声明路线的方式:
有关带有正则表达式的路由在文档中可用。
但是,公平地说,在这种情况下,创建两个单独的入口处似乎更容易:
You can specify a route using regular expressions.
Assuming the id is a number:
and then read the value:
This is how I usually declare the route using Vert.x Web 4.3.1:
More details about routing with regular expressions are available in the documentation.
But, to be fair, creating two separate entry points seems easier for this case: