parameterMultiMap
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
-
source
val 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
-
source
import static org.apache.pekko.http.javadsl.server.Directives.complete; import static org.apache.pekko.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");
1.1.0