mapHttpResponseEntity

Changes the response entity that was generated by the inner route.

Signature

def mapHttpResponseEntity(f: HttpEntity  HttpEntity): Directive0 

Description

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

See Directives transforming the response for similar directives.

Example

def prefixEntity(entity: HttpEntity): HttpEntity =
  HttpEntity(HttpData("test") +: entity.data)
val prefixWithTest: Directive0 = mapHttpResponseEntity(prefixEntity)
val route = prefixWithTest(complete("abc"))

Get("/") ~> route ~> check {
  responseAs[String] === "testabc"
}