extractMatchedPath
Description
Extracts the matched path from the request context.
The extractMatchedPath
directive extracts the path that was already 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 use already matched part in their logic.
See also extractUnmatchedPath to see similar directive for unmatched path.
Example
- Scala
-
source
val route = pathPrefix("abc") { extractMatchedPath { matched => complete(matched.toString) } } // tests: Get("/abc") ~> route ~> check { responseAs[String] shouldEqual "/abc" } Get("/abc/xyz") ~> route ~> check { responseAs[String] shouldEqual "/abc" }
- Java
-
source
import static org.apache.pekko.http.javadsl.server.Directives.extractMatchedPath; final Route route = pathPrefix("abc", () -> extractMatchedPath(Directives::complete)); // tests: testRoute(route).run(HttpRequest.GET("/abc")).assertEntity("/abc"); testRoute(route).run(HttpRequest.GET("/abc/xyz")).assertEntity("/abc");
1.1.0