This documentation regards version 10.1, however the current version is 10.7.0.
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
- Scala
-
source
val route = path("sample") { extractMaterializer { materializer => complete { // explicitly use the `materializer`: Source.single(s"Materialized by ${materializer.##}!") .runWith(Sink.head)(materializer) } } } // default materializer will be used // tests: Get("/sample") ~> route ~> check { responseAs[String] shouldEqual s"Materialized by ${materializer.##}!" }
- Java