parameterSeqparameterList

Signature

def parameterSeq: Directive1[immutable.Seq[(String, String)]] 

Description

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

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

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

Example

Scala
sourceval route =
  parameterSeq { params =>
    def paramString(param: (String, String)): String = s"""${param._1} = '${param._2}'"""
    complete(s"The parameters are ${params.map(paramString).mkString(", ")}")
  }

// tests:
Get("/?color=blue&count=42") ~> route ~> check {
  responseAs[String] shouldEqual "The parameters are color = 'blue', count = '42'"
}
Get("/?x=1&x=2") ~> route ~> check {
  responseAs[String] shouldEqual "The parameters are x = '1', x = '2'"
}
Java
sourceimport static org.apache.pekko.http.javadsl.server.Directives.complete;
import static org.apache.pekko.http.javadsl.server.Directives.parameterList;

final Function<Entry, String> paramString =
    entry -> entry.getKey() + " = '" + entry.getValue() + "'";

final Route route =
    parameterList(
        params -> {
          final String pString =
              params.stream().map(paramString::apply).collect(Collectors.joining(", "));

          return complete("The parameters are " + pString);
        });

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

testRoute(route)
    .run(HttpRequest.GET("/?x=1&x=2"))
    .assertEntity("The parameters are x = '1', x = '2'");