最后一个path元素是可选的,因此我创建了此匹配器
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]) =>
// ...
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句