mapSettings
Description
Transforms the RoutingSettingsRoutingSettings with a RoutingSettings ⇒ RoutingSettings
functionFunction<RoutingSettings, RoutingSettings>
.
See also withSettings or extractSettings.
Example
- Scala
-
val special = RoutingSettings(system).withFileIODispatcher("special-io-dispatcher") def sample() = path("sample") { complete { // internally uses the configured fileIODispatcher: val source = FileIO.fromPath(Paths.get("example.json")) HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, source)) } } val route = get { pathPrefix("special") { withSettings(special) { sample() // `special` file-io-dispatcher will be used to read the file } } ~ sample() // default file-io-dispatcher will be used to read the file } // tests: Post("/special/sample") ~> route ~> check { responseAs[String] shouldEqual s"{}" } Get("/sample") ~> route ~> check { responseAs[String] shouldEqual "{}" }
- Java
-
final Route route = mapSettings(settings -> settings.withFileGetConditional(false), () -> extractSettings(settings -> complete("RoutingSettings.fileGetConditional = " + settings.getFileGetConditional()) ) ); // tests: testRoute(route).run(HttpRequest.GET("/")) .assertEntity("RoutingSettings.fileGetConditional = false");