parameter
Description
Extracts a query parameter value from the request .
In the Scala API, parameter
is an alias for parameters
and you can use both directives to extract any number of parameter values. For a detailed description about how to extract one or more parameters see parameters.
See When to use which parameter directive? to understand when to use which directive.
Example
- Scala
-
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'" }
- Java