extractRequest

extractRequest

Signature

Description

Extracts the complete HttpRequest instance.

Use extractRequest to extract just the complete URI of the request. Usually there's little use of extracting the complete request because extracting of most of the aspects of HttpRequests is handled by specialized directives. See Directives filtering or extracting from the request.

Example

val route =
  extractRequest { request =>
    complete(s"Request method is ${request.method.name} and content-type is ${request.entity.contentType}")
  }

// tests:
Post("/", "text") ~> route ~> check {
  responseAs[String] shouldEqual "Request method is POST and content-type is text/plain; charset=UTF-8"
}
Get("/") ~> route ~> check {
  responseAs[String] shouldEqual "Request method is GET and content-type is none/none"
}

Contents