formFieldMultiMap

formFieldMultiMap

§Signature

§Description

Extracts all HTTP form fields at once as a multi-map of type Map[String, List[String] mapping a form name to a list of all its values.

This directive can be used if form fields can occur several times.

The order of values is not specified.

See formFields for an in-depth description.

§Warning

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

§Example

  1. val route =
  2. formFieldMultiMap { fields =>
  3. complete("There are " +
  4. s"form fields ${fields.map(x => x._1 + " -> " + x._2.size).mkString(", ")}")
  5. }
  6.  
  7. // tests:
  8. Post("/", FormData("color" -> "blue", "count" -> "42")) ~> route ~> check {
  9. responseAs[String] shouldEqual "There are form fields color -> 1, count -> 1"
  10. }
  11. Post("/", FormData("x" -> "23", "x" -> "4", "x" -> "89")) ~> route ~> check {
  12. responseAs[String] shouldEqual "There are form fields x -> 3"
  13. }