parameter

Extracts a query parameter value from the request.

Description

See parameter-java for a detailed description of this directive.

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

Example

final Route route = parameter("color", color ->
  complete("The color is '" + color + "'")
);

// tests:
testRoute(route).run(HttpRequest.GET("/?color=blue"))
  .assertEntity("The color is 'blue'");

testRoute(route).run(HttpRequest.GET("/"))
  .assertStatusCode(StatusCodes.NOT_FOUND)
  .assertEntity("Request is missing required query parameter 'color'");
The source code for this page can be found here.