Loading
extractMethod
Extracts the HttpMethod from the request context and provides it for use for other directives explicitly.
Example
In the below example our route first matches all GET requests, and if an incoming request wasn't a GET, the matching continues and the extractMethod route will be applied which we can use to programatically print what type of request it was - independent of what actual HttpMethod it was:
final RequestVal<HttpMethod> requestMethod = RequestVals.requestMethod();
final Route otherMethod = handleWith1(
requestMethod,
(ctx, method) -> ctx.complete("This " + method.value()
+ " request, clearly is not a GET!"));
final Route route = route(get(complete("This is a GET request.")),
otherMethod);
testRoute(route).run(HttpRequest.GET("/")).assertEntity(
"This is a GET request.");
testRoute(route).run(HttpRequest.PUT("/").withEntity("put content"))
.assertEntity("This PUT request, clearly is not a GET!");
testRoute(route).run(HttpRequest.HEAD("/")).assertEntity(
"This HEAD request, clearly is not a GET!");
Contents