pathSingleSlash

Description

Only passes the request to its inner route if the unmatched path of the RequestContext contains exactly one single slash.

This directive is a simple alias for pathPrefix(PathEnd) and is mostly used for matching requests to the root URI (/) on an inner-level to discriminate “all path segments matched” from other alternatives (see the example below). For a comparison between path directives check Overview of path directives.

Example

final Route route = 
    route(
        pathSingleSlash(() -> complete("root")),
        pathPrefix("ball", () -> 
            route(
                pathSingleSlash(() -> complete("/ball/")),
                path(integerSegment(), (i) -> complete((i % 2 == 0) ? "even ball" : "odd ball"))
            )
        )
    );
// tests:
testRoute(route).run(HttpRequest.GET("/")).assertEntity("root");
testRoute(route).run(HttpRequest.GET("/ball")).assertStatusCode(StatusCodes.NOT_FOUND);
testRoute(route).run(HttpRequest.GET("/ball/")).assertEntity("/ball/");
testRoute(route).run(HttpRequest.GET("/ball/1337")).assertEntity("odd ball");
The source code for this page can be found here.