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

  1. val route =
  2. pathSingleSlash {
  3. complete("root")
  4. } ~
  5. pathPrefix("ball") {
  6. pathSingleSlash {
  7. complete("/ball/")
  8. } ~
  9. path(IntNumber) { int =>
  10. complete(if (int % 2 == 0) "even ball" else "odd ball")
  11. }
  12. }
  13.  
  14. // tests:
  15. Get("/") ~> route ~> check {
  16. responseAs[String] shouldEqual "root"
  17. }
  18.  
  19. Get("/ball") ~> route ~> check {
  20. handled shouldEqual false
  21. }
  22.  
  23. Get("/ball/") ~> route ~> check {
  24. responseAs[String] shouldEqual "/ball/"
  25. }
  26.  
  27. Get("/ball/1337") ~> route ~> check {
  28. responseAs[String] shouldEqual "odd ball"
  29. }