extractUnmatchedPath
Description
Extracts the unmatched path from the request context.
The extractUnmatchedPath
directive extracts the remaining path that was not yet matched by any of the PathDirectives (or any custom ones that change the unmatched path field of the request context). You can use it for building directives that handle complete suffixes of paths (like the getFromDirectory
directives and similar ones).
Use mapUnmatchedPath
to change the value of the unmatched path.
See also extractMatchedPath to see similar directive for matched path.
Example
- Scala
-
source
val route = pathPrefix("abc") { extractUnmatchedPath { remaining => complete(s"Unmatched: '$remaining'") } } // tests: Get("/abc") ~> route ~> check { responseAs[String] shouldEqual "Unmatched: ''" } Get("/abc/456") ~> route ~> check { responseAs[String] shouldEqual "Unmatched: '/456'" }
- Java
-
source
import static org.apache.pekko.http.javadsl.server.Directives.complete; import static org.apache.pekko.http.javadsl.server.Directives.extractUnmatchedPath; final Route route = pathPrefix( "abc", () -> extractUnmatchedPath(remaining -> complete("Unmatched: '" + remaining + "'"))); // tests: testRoute(route).run(HttpRequest.GET("/abc")).assertEntity("Unmatched: ''"); testRoute(route).run(HttpRequest.GET("/abc/456")).assertEntity("Unmatched: '/456'");
1.0.1