parameter

parameter

§Signature

§Description

Extracts a query parameter value from the request.

See parameters for a detailed description of this directive.

See When to use which parameter directive? to understand when to use which directive.

§Example

  1. val route =
  2. parameter('color) { color =>
  3. complete(s"The color is '$color'")
  4. }
  5.  
  6. // tests:
  7. Get("/?color=blue") ~> route ~> check {
  8. responseAs[String] shouldEqual "The color is 'blue'"
  9. }
  10.  
  11. Get("/") ~> Route.seal(route) ~> check {
  12. status shouldEqual StatusCodes.NotFound
  13. responseAs[String] shouldEqual "Request is missing required query parameter 'color'"
  14. }