extractRequestContext

extractRequestContext

Description

Extracts the request's underlying RequestContext.

This directive is used as a building block for most of the other directives, which extract the context and by inspecting some of it's values can decide what to do with the request - for example provide a value, or reject the request.

See also extractRequest if only interested in the HttpRequest instance itself.

Example

final Route route = extractRequestContext(ctx -> {
  ctx.getLog().debug("Using access to additional context availablethings, like the logger.");
  final HttpRequest request = ctx.getRequest();
  return complete("Request method is " + request.method().name() +
                    " and content-type is " + request.entity().getContentType());
});

// tests:
testRoute(route).run(HttpRequest.POST("/").withEntity("text"))
  .assertEntity("Request method is POST and content-type is text/plain; charset=UTF-8");
testRoute(route).run(HttpRequest.GET("/"))
  .assertEntity("Request method is GET and content-type is none/none");

Contents