mapSettings

Signature

def mapSettings(f: RoutingSettings => RoutingSettings): Directive0

Description

Transforms the RoutingSettingsRoutingSettings with a RoutingSettings => RoutingSettings functionFunction<RoutingSettings, RoutingSettings>.

See also withSettings or extractSettings.

Example

Scala
sourceval tunedSettings = mapSettings { settings =>
  settings.withFileGetConditional(false)
}

val route =
  tunedSettings {
    extractSettings { (settings: RoutingSettings) =>
      complete(s"RoutingSettings.fileGetConditional = ${settings.fileGetConditional}")
    }
  }

// tests:
Get("/") ~> route ~> check {
  responseAs[String] shouldEqual s"RoutingSettings.fileGetConditional = false"
}
Java
sourceimport static akka.http.javadsl.server.Directives.mapSettings;

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");
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.