Changes the message the inner route sends to the responder.


def mapRouteResponsePF(f: PartialFunction[Any, Any]): Directive0 


The mapRouteResponsePF directive is used as a building block for Custom Directives to transform what the inner route sends to the responder (see The Responder Chain). It’s similar to the mapRouteResponse directive but allows to specify a partial function that doesn’t have to handle all the incoming response messages.

See Directives hooking into the responder chain for similar directives.


case object MyCustomRejection extends Rejection
val rejectRejections = // not particularly useful directive
  mapRouteResponsePF {
    case Rejected(_) => Rejected(List(AuthorizationFailedRejection))
val route =
  rejectRejections {

Get("/") ~> route ~> check {
  rejection === AuthorizationFailedRejection