provide

Signature

def provide[T](value: T): Directive1[T]

Description

Provides a constant value to the inner route.

The provide directive is used as a building block for Custom Directives to provide a single value to the inner route. To provide several values use the tprovide directive.

See Providing Values to Inner Routes for an overview of similar directives.

Example

Scala
def providePrefixedString(value: String): Directive1[String] = provide("prefix:" + value)
val route =
  providePrefixedString("test") { value =>
    complete(value)
  }

// tests:
Get("/") ~> route ~> check {
  responseAs[String] shouldEqual "prefix:test"
}
Java
import static akka.http.javadsl.server.Directives.provide;

final Route route = providePrefixedStringRoute("test");

// tests:
testRoute(route).run(HttpRequest.GET("/"))
  .assertEntity("prefix:test");
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.