gpt4 book ai didi

swift - Steam 3 : Route with arbitrary path segments

转载 作者:搜寻专家 更新时间:2023-10-31 19:35:47 24 4
gpt4 key购买 nike

我正在开发一个 Vapor 3 应用程序,它使用请求路径作为响应方法的参数。例如:

http://localhost:8080/monitor/some/test/path

这可以由单个端点处理,在本例中为 monitor 端点,然后理想情况下我可以访问 URL 的其余部分,/some/test/path.

我在 Vapor 中编写了一条无法使用通配符变量的路由,并尝试了文档中描述的 group 机制,但无济于事。我对使用其他 Web 框架的期望是像“/monitor/*”这样的东西应该可以完成这项工作,但我在文档中找不到任何建议。

如有任何帮助,我们将不胜感激!

最佳答案

如果要匹配任何单个路径参数,请使用any 路径组件。如果要匹配任意数量的路径参数,请使用 all 路径组件。

例如,如果我用这些路径组件注册一个路由:

"service", any, "api", "users"

它将匹配这些路由:

  • /service/v1/api/users
  • /service/caleb/api/users

但它不会匹配这些:

  • service/v1/beta/api/users
  • 服务/v1

但是,如果您使用 all 组件,如下所示:

"service", "api", all

您可以匹配以下任何一项:

  • /service/api/v1
  • /service/api/v1/users/caleb

但不是/service/api

关于swift - Steam 3 : Route with arbitrary path segments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53917339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com