mapResponseEntity
Signature
def mapResponseEntity(f: ResponseEntity ⇒ ResponseEntity): Directive0
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
def prefixEntity(entity: ResponseEntity): ResponseEntity = entity match {
case HttpEntity.Strict(contentType, data) =>
HttpEntity.Strict(contentType, ByteString("test") ++ data)
case _ => throw new IllegalStateException("Unexpected entity type")
}
val prefixWithTest: Directive0 = mapResponseEntity(prefixEntity)
val route = prefixWithTest(complete("abc"))
// tests:
Get("/") ~> route ~> check {
responseAs[String] shouldEqual "testabc"
}