在 akka-http 中,如何将路径段与可选的结束斜杠匹配?
in akka-http, how to match a path segment with an optional end slash?
akka http 的这个路径指令匹配 /hello
lazy val userRoutes: Route = cors() {
path(Segment) { p => ... }
如何匹配 /hello
和 /hello/
(可选的结束斜线)?
阅读文档后https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/path-directives/index.html#pathdirectives
我试过如下,但它没有编译:
lazy val userRoutes: Route = cors() {
rawPathPrefix(Slash ~ Segment ~ pathEndOrSingleSlash) { p => ... }
Akka-Http 提供了路径指令,您可以使用它来解决以下问题。
val route =
pathPrefix("hello") {
pathEndOrSingleSlash {
complete("/hello")
}
}
akka http 的这个路径指令匹配 /hello
lazy val userRoutes: Route = cors() {
path(Segment) { p => ... }
如何匹配 /hello
和 /hello/
(可选的结束斜线)?
阅读文档后https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/path-directives/index.html#pathdirectives 我试过如下,但它没有编译:
lazy val userRoutes: Route = cors() {
rawPathPrefix(Slash ~ Segment ~ pathEndOrSingleSlash) { p => ... }
Akka-Http 提供了路径指令,您可以使用它来解决以下问题。
val route =
pathPrefix("hello") {
pathEndOrSingleSlash {
complete("/hello")
}
}