parameterMultiMap

Signature

def parameterMultiMap: Directive1[Map[String, List[String]]]

Description

Extracts all parameters at once as a multi-map of type Map[String, List[String]]Map<String, List<String>> mapping a parameter name to a list of all its values.

This directive can be used if parameters can occur several times.

The order of values is not specified.

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

Example

Scala
sourceval route =
  parameterMultiMap { params =>
    complete(s"There are parameters ${params.map(x => x._1 + " -> " + x._2.size).mkString(", ")}")
  }

// tests:
Get("/?color=blue&count=42") ~> route ~> check {
  responseAs[String] shouldEqual "There are parameters color -> 1, count -> 1"
}
Get("/?x=23&x=42") ~> route ~> check {
  responseAs[String] shouldEqual "There are parameters x -> 2"
}
Java
sourceimport static akka.http.javadsl.server.Directives.complete;
import static akka.http.javadsl.server.Directives.parameterMultiMap;

final Route route = parameterMultiMap(params -> {
  final String pString = params.entrySet()
    .stream()
    .map(e -> e.getKey() + " -> " + e.getValue().size())
    .collect(Collectors.joining(", "));
  return complete("There are parameters " + pString);
});

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

testRoute(route).run(HttpRequest.GET("/?x=23&x=42"))
  .assertEntity("There are parameters x -> 2");
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.