parameterMap

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

  1. final Function<Entry, String> paramString =
  2. entry -> entry.getKey() + " = '" + entry.getValue() + "'";
  3.  
  4. final Route route = parameterMap(params -> {
  5. final String pString = params.entrySet()
  6. .stream()
  7. .map(paramString::apply)
  8. .collect(Collectors.joining(", "));
  9. return complete("The parameters are " + pString);
  10. });
  11.  
  12. // tests:
  13. testRoute(route).run(HttpRequest.GET("/?color=blue&count=42"))
  14. .assertEntity("The parameters are color = 'blue', count = '42'");
  15.  
  16. testRoute(route).run(HttpRequest.GET("/?x=1&x=2"))
  17. .assertEntity("The parameters are x = '2'");