mapRouteResult

Signature

def mapRouteResult(f: RouteResult ⇒ RouteResult): Directive0

Description

Changes the message the inner route sends to the responder.

The mapRouteResult directive is used as a building block for Custom Directives to transform the RouteResult coming back from the inner route.

See Result Transformation Directives for similar directives.

Example

val rejectAll = // not particularly useful directive
  mapRouteResult {
    case _ => Rejected(List(AuthorizationFailedRejection))
  }
val route =
  rejectAll {
    complete("abc")
  }

// tests:
Get("/") ~> route ~> check {
  rejections.nonEmpty shouldEqual true
}
The source code for this page can be found here.