This documentation regards version 10.1, however the current version is 10.7.0.

extractActorSystem

Signature

def extractActorSystem: Directive1[ActorSystem] = extract { ctx

Description

Extracts the ActorSystem from the RequestContext, which can be useful when the external API in your route needs one.

Warning

This is only supported when the available Materializer is an ActorMaterializer.

Example

Scala
sourceval route = extractActorSystem { actorSystem =>
  complete(s"Actor System extracted, hash=${actorSystem.hashCode()}")
}

// tests:
Get("/") ~> route ~> check {
  responseAs[String] shouldEqual s"Actor System extracted, hash=${system.hashCode()}"
}
Java
sourceimport static akka.http.javadsl.server.Directives.extractActorSystem;

final Route route = extractActorSystem(actorSystem ->
  complete("Actor System extracted, hash=" + actorSystem.hashCode())
);

// tests:
testRoute(route).run(HttpRequest.GET("/"))
  .assertEntity("Actor System extracted, hash=" + system().hashCode());
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.