akka 路径匹配最后一个可选元素

akka path match on last optional element

最后一个路径元素是可选的,所以我创建了这个匹配器

pathPrefix("the-endpoint" / Segment / Segment.?) { (left[String], right: Option[String]) => ... }

问题是只有在我添加尾随的“/”斜杠字符时才会调用此路径:

即不要添加最后的路径部分:

curl localhost:12345/the-endpoint/firstsegment
The requested resource could not be found

但是

curl localhost:12345/the-endpoint/firstsegment/
... all good , gets to the path as expected ...

您可以使用 ignoreTrailingSlash 指令:

ignoreTrailingSlash {
  path("the-endpoint" / Segment / Segment.?) { (left: String, right: Option[String]) =>
    // ...
  }
}