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