extract

Calculates a value from the request context and provides the value to the inner route.

Signature

def extract[T](f: RequestContext  T): Directive1[T] 

Description

The extract directive is used as a building block for Custom Directives to extract data from the RequestContext and provide it to the inner route. It is a special case for extracting one value of the more general hextract directive that can be used to extract more than one value.

See Directives to provide values to inner routes for an overview of similar directives.

Example

val uriLength = extract(_.request.uri.toString.length)
val route =
  uriLength { len =>
    complete(s"The length of the request URI is $len")
  }

Get("/abcdef") ~> route ~> check {
  responseAs[String] === "The length of the request URI is 25"
}