mapUnmatchedPath

Description

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

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

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

Example

final Function<String, String> ignore456 = path -> {
  int slashPos = path.indexOf("/");
  if (slashPos != -1) {
    String head = path.substring(0, slashPos);
    String tail = path.substring(slashPos);
    if (head.length() <= 3) {
      return tail;
    } else {
      return path.substring(3);
    }
  } else {
    return path;
  }
};

final Route route = pathPrefix("123", () ->
  mapUnmatchedPath(ignore456, () ->
    path("abc", () ->
      complete("Content")
    )
  )
);

// tests:
testRoute(route).run(HttpRequest.GET("/123/abc"))
  .assertEntity("Content");
testRoute(route).run(HttpRequest.GET("/123456/abc"))
  .assertEntity("Content");
The source code for this page can be found here.