pathEndOrSingleSlash
Only passes the request to its inner route if the unmatched path of the RequestContext is either empty or contains only one single slash.
Signature
def pathEndOrSingleSlash: Directive0
Description
This directive is a simple alias for rawPathPrefix(Slash.? ~ PathEnd) and is mostly used on an inner-level to discriminate “path already fully matched” from other alternatives (see the example below).
It is equivalent to pathEnd | pathSingleSlash but slightly more efficient.
Example
val route =
pathPrefix("foo") {
pathEndOrSingleSlash {
complete("/foo")
} ~
path("bar") {
complete("/foo/bar")
}
}
Get("/foo") ~> route ~> check {
responseAs[String] === "/foo"
}
Get("/foo/") ~> route ~> check {
responseAs[String] === "/foo"
}
Get("/foo/bar") ~> route ~> check {
responseAs[String] === "/foo/bar"
}