extractRequest

Signature

def extractRequest: Directive1[HttpRequest]

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 Request Directives.

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"
}
The source code for this page can be found here.