textract

textract

§Signature

§Description

Extracts a tuple of values from the request context and provides them to the inner route.

The textract directive is used as a building block for Custom Directives to extract data from the RequestContext and provide it to the inner route. To extract just one value use the extract directive. To provide a constant value independent of the RequestContext use the tprovide directive instead.

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

See also extract for extracting a single value.

§Example

  1. val pathAndQuery = textract { ctx =>
  2. val uri = ctx.request.uri
  3. (uri.path, uri.query())
  4. }
  5. val route =
  6. pathAndQuery { (p, query) =>
  7. complete(s"The path is $p and the query is $query")
  8. }
  9.  
  10. // tests:
  11. Get("/abcdef?ghi=12") ~> route ~> check {
  12. responseAs[String] shouldEqual "The path is /abcdef and the query is ghi=12"
  13. }