pathEnd • Akka HTTP (original) (raw)
Signature
def pathEnd: Directive0
Description
Only passes the request to its inner route if the unmatched path of the RequestContextRequestContext is empty, i.e. the request path has been fully matched by a higher-level path or pathPrefix directive.
This directive is a simple alias for rawPathPrefix(PathEnd)
and is mostly used on an inner-level to discriminate “path already fully matched” from other alternatives (see the example below). For a comparison between path directives check Overview of path directives.
Example
Scala
source`val route = pathPrefix("foo") { concat( pathEnd { complete("/foo") }, path("bar") { complete("/foo/bar") } ) }
// tests: Get("/foo") ~> route ~> check { responseAs[String] shouldEqual "/foo" }
Get("/foo/") ~> route ~> check { handled shouldEqual false }
Get("/foo/bar") ~> route ~> check { responseAs[String] shouldEqual "/foo/bar" }`
Java
source`final Route route = concat( pathPrefix("foo", () -> concat( pathEnd(() -> complete("/foo")), path("bar", () -> complete("/foo/bar")) ) ) );
// tests: testRoute(route).run(HttpRequest.GET("/foo")).assertEntity("/foo"); testRoute(route).run(HttpRequest.GET("/foo/")).assertStatusCode(StatusCodes.NOT_FOUND); testRoute(route).run(HttpRequest.GET("/foo/bar")).assertEntity("/foo/bar");`
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.