rewriteUnmatchedPath

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

Signature

def rewriteUnmatchedPath(f: Uri.Path  Uri.Path): Directive0 

Description

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

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

Example

def ignore456(path: Path) = path match {
  case s@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 = rewriteUnmatchedPath(ignore456)

val route =
  pathPrefix("123") {
    ignoring456 {
      path("abc") {
        complete(s"Content")
      }
    }
  }

Get("/123/abc") ~> route ~> check {
  responseAs[String] === "Content"
}
Get("/123456/abc") ~> route ~> check {
  responseAs[String] === "Content"
}