mapUnmatchedPath

mapUnmatchedPath

§Signature

§Description

Transforms the unmatchedPath field of the request context for inner routes.

The mapUnmatchedPath directive is used as a building block for writing Custom Directives. You can use it for implementing custom path matching directives.

Use extractUnmatchedPath for extracting the current value of the unmatched path.

§Example

  1. def ignore456(path: Uri.Path) = path match {
  2. case s @ Uri.Path.Segment(head, tail) if head.startsWith("456") =>
  3. val newHead = head.drop(3)
  4. if (newHead.isEmpty) tail
  5. else s.copy(head = head.drop(3))
  6. case _ => path
  7. }
  8. val ignoring456 = mapUnmatchedPath(ignore456)
  9.  
  10. val route =
  11. pathPrefix("123") {
  12. ignoring456 {
  13. path("abc") {
  14. complete("Content")
  15. }
  16. }
  17. }
  18.  
  19. // tests:
  20. Get("/123/abc") ~> route ~> check {
  21. responseAs[String] shouldEqual "Content"
  22. }
  23. Get("/123456/abc") ~> route ~> check {
  24. responseAs[String] shouldEqual "Content"
  25. }