routeRouteResponse

Replaces the message the inner route sends to the responder with the result of a new route.

Signature

def routeRouteResponse(f: PartialFunction[Any, Route]): Directive0 

Description

The routeRouteResponse directive is used as a building block for Custom Directives to replace what the inner route sends to the responder (see The Responder Chain) with the result of a completely new route.

See Directives hooking into the responder chain for similar directives.

Example

val completeWithRejectionNames =
  routeRouteResponse {
    case Rejected(rejs) => complete(s"Got these rejections: ${rejs.map(_.getClass.getSimpleName).mkString(", ")}")
  }

val route = completeWithRejectionNames {
  reject(AuthorizationFailedRejection) ~
  post(complete("post"))
}
Get("/") ~> route ~> check {
  responseAs[String] === "Got these rejections: AuthorizationFailedRejection$, MethodRejection"
}