This documentation regards version 10.1, however the current version is 10.7.0.
pathSingleSlash
Description
Only passes the request to its inner route if the unmatched path of the RequestContext
contains exactly one single slash.
This directive is a simple alias for pathPrefix(PathEnd)
and is mostly used for matching requests to the root URI (/
) on an inner-level to discriminate “all path segments matched” from other alternatives (see the example below). For a comparison between path directives check Overview of path directives.
Example
- Scala
-
source
val route = concat( pathSingleSlash { complete("root") }, pathPrefix("ball") { concat( pathSingleSlash { complete("/ball/") }, path(IntNumber) { int => complete(if (int % 2 == 0) "even ball" else "odd ball") } ) } ) // tests: Get("/") ~> route ~> check { responseAs[String] shouldEqual "root" } Get("/ball") ~> route ~> check { handled shouldEqual false } Get("/ball/") ~> route ~> check { responseAs[String] shouldEqual "/ball/" } Get("/ball/1337") ~> route ~> check { responseAs[String] shouldEqual "odd ball" }
- Java