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

val route =
  parameter('color) { color =>
    complete(s"The color is '$color'")
  }

// tests:
Get("/?color=blue") ~> route ~> check {
  responseAs[String] shouldEqual "The color is 'blue'"
}

Get("/") ~> Route.seal(route) ~> check {
  status shouldEqual StatusCodes.NotFound
  responseAs[String] shouldEqual "Request is missing required query parameter 'color'"
}

Contents