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
- def ignore456(path: Uri.Path) = path match {
- case s @ Uri.Path.Segment(head, tail) if head.startsWith("456") =>
- val newHead = head.drop(3)
- if (newHead.isEmpty) tail
- else s.copy(head = head.drop(3))
- case _ => path
- }
- val ignoring456 = mapUnmatchedPath(ignore456)
-
- val route =
- pathPrefix("123") {
- ignoring456 {
- path("abc") {
- complete("Content")
- }
- }
- }
-
- // tests:
- Get("/123/abc") ~> route ~> check {
- responseAs[String] shouldEqual "Content"
- }
- Get("/123456/abc") ~> route ~> check {
- responseAs[String] shouldEqual "Content"
- }
Contents