formFieldList

formFieldList

Description

Extracts all HTTP form fields at once in the original order as (name, value) tuples of type Map.Entry<String, String>.

This directive can be used if the exact order of form fields is important or if parameters can occur several times.

Warning

The directive reads all incoming HTT form fields without any configured upper bound. It means, that requests with form fields holding significant amount of data (ie. during a file upload) can cause performance issues or even an OutOfMemoryError s.

Example

final Function<List<Entry<String, String>>, String> listToString = list ->
  list.stream()
    .map(e -> e.getKey() + " = '" + e.getValue() +"'")
    .collect(Collectors.joining(", "));

final Route route = formFieldList(fields ->
  complete("The form fields are " + listToString.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", "23"),
    Pair.create("x", "4"),
    Pair.create("x", "89"));
testRoute(route).run(HttpRequest.POST("/").withEntity(formDataSameKey.toEntity()))
  .assertEntity("The form fields are x = '23', x = '4', x = '89'");

Contents