mapResponseEntity

Description

The mapResponseEntity directive is used as a building block for Custom Directives to transform a response entity that was generated by the inner route.

See Response Transforming Directives for similar directives.

Example

final Function<ResponseEntity, ResponseEntity> prefixEntity = entity -> {
  if (entity instanceof HttpEntity.Strict) {
    final HttpEntity.Strict strict = (HttpEntity.Strict) entity;
    return HttpEntities.create(
      strict.getContentType(),
      ByteString.fromString("test").concat(strict.getData()));
  } else {
    throw new IllegalStateException("Unexpected entity type");
  }
};

final Route route = mapResponseEntity(prefixEntity, () -> complete("abc"));

testRoute(route).run(HttpRequest.GET("/"))
  .assertEntity("testabc");
The source code for this page can be found here.