extractMaterializer

Description

Extracts the Materializer from the RequestContext, which can be useful when you want to run an Akka Stream directly in your route.

See also withMaterializer to see how to customise the used materializer for specific inner routes.

Example

final Route route = path("sample", () ->
  extractMaterializer(mat ->
    onSuccess(() ->
      // explicitly use the materializer:
      Source.single("Materialized by " + mat.hashCode() + "!")
        .runWith(Sink.head(), mat), this::complete
    )
  )
); // default materializer will be used

testRoute(route).run(HttpRequest.GET("/sample"))
  .assertEntity("Materialized by " + materializer().hashCode()+ "!");
The source code for this page can be found here.