pathSingleSlash

pathSingleSlash

Signature

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).

Example

val route =
  pathSingleSlash {
    complete("root")
  } ~
    pathPrefix("ball") {
      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"
}

Contents