pathSingleSlash

Only passes the request to its inner route if the unmatched path of the RequestContext contains exactly one single slash.

Signature

def pathSingleSlash: Directive0 

Description

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")
    }
  }

Get("/") ~> route ~> check {
  responseAs[String] === "root"
}

Get("/ball") ~> route ~> check {
  handled === false
}

Get("/ball/") ~> route ~> check {
  responseAs[String] === "/ball/"
}

Get("/ball/1337") ~> route ~> check {
  responseAs[String] === "odd ball"
}