formFieldMap

formFieldMap

Description

Extracts all HTTP form fields at once as a Map<String, String> mapping form field names to form field values.

If form data contain a field value several times, the map will contain the last one.

Warning

Use of this directive can result in performance degradation or even in OutOfMemoryError s. See formFieldList for details.

Example

final Function<Map<String, String>, String> mapToString = map ->
  map.entrySet()
    .stream()
    .map(e -> e.getKey() + " = '" + e.getValue() +"'")
    .collect(Collectors.joining(", "));


final Route route = formFieldMap(fields ->
  complete("The form fields are " + mapToString.apply(fields))
);

// tests:
final FormData formDataDiffKey =
  FormData.create(
    Pair.create("color", "blue"),
    Pair.create("count", "42"));
testRoute(route).run(HttpRequest.POST("/").withEntity(formDataDiffKey.toEntity()))
  .assertEntity("The form fields are color = 'blue', count = '42'");

final FormData formDataSameKey =
  FormData.create(
    Pair.create("x", "1"),
    Pair.create("x", "5"));
testRoute(route).run(HttpRequest.POST("/").withEntity(formDataSameKey.toEntity()))
  .assertEntity( "The form fields are x = '5'");

Contents