mapInnerRoute

Signature

def mapInnerRoute(f: Route 

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
sourceval 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
sourceimport static org.apache.pekko.http.javadsl.server.Directives.mapInnerRoute;

// TODO: implement mapInnerRoute