parameterMap

Extracts all parameters at once as a Map<String, String> mapping parameter names to parameter values.

Description

If a query contains a parameter value several times, the map will contain the last one.

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

Example

final Function<Entry, String> paramString =
  entry -> entry.getKey() + " = '" + entry.getValue() + "'";

final Route route = parameterMap(params -> {
  final String pString = params.entrySet()
    .stream()
    .map(paramString::apply)
    .collect(Collectors.joining(", "));
  return complete("The parameters are " + pString);
});

// tests:
testRoute(route).run(HttpRequest.GET("/?color=blue&count=42"))
  .assertEntity("The parameters are color = 'blue', count = '42'");

testRoute(route).run(HttpRequest.GET("/?x=1&x=2"))
  .assertEntity("The parameters are x = '2'");
The source code for this page can be found here.