mapInnerRoute

Signature

def mapInnerRoute(f: Route ⇒ Route): Directive0

Description

Changes the execution model of the inner route by wrapping it with arbitrary logic.

The mapInnerRoute directive is used as a building block for Custom Directives to replace the inner route with any other route. Usually, the returned route wraps the original one with custom execution logic.

Example

Scala
val completeWithInnerException =
  mapInnerRoute { route => ctx =>
    try {
      route(ctx)
    } catch {
      case NonFatal(e) => ctx.complete(s"Got ${e.getClass.getSimpleName} '${e.getMessage}'")
    }
  }

val route =
  completeWithInnerException {
    complete(throw new IllegalArgumentException("BLIP! BLOP! Everything broke"))
  }

// tests:
Get("/") ~> route ~> check {
  responseAs[String] shouldEqual "Got IllegalArgumentException 'BLIP! BLOP! Everything broke'"
}
Java
import static akka.http.javadsl.server.Directives.mapInnerRoute;

// TODO: implement mapInnerRoute
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.