requestEntityPresent

Description

A simple filter that checks if the request entity is present and only then passes processing to the inner route. Otherwise, the request is rejected with RequestEntityExpectedRejection.

See also requestEntityEmpty for the opposite effect.

Example

final Route route = requestEntityEmpty(() ->
  complete("request entity empty")
).orElse(requestEntityPresent(() ->
  complete("request entity present")
));

// tests:
testRoute(route).run(HttpRequest.POST("/"))
  .assertEntity("request entity empty");
testRoute(route).run(HttpRequest.POST("/").withEntity("foo"))
  .assertEntity("request entity present");
The source code for this page can be found here.