formFieldMap
Description
Extracts all HTTP form fields at once as a Map[String, String]
mapping form field names to form field values. Data posted from HTML Forms is either of type application/x-www-form-urlencoded
or of type multipart/form-data
.
If form data contain a field value several times, the map will contain the last one.
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
- Scala
-
val route = formFieldMap { fields => def formFieldString(formField: (String, String)): String = s"""${formField._1} = '${formField._2}'""" complete(s"The form fields are ${fields.map(formFieldString).mkString(", ")}") } // tests: Post("/", FormData("color" -> "blue", "count" -> "42")) ~> route ~> check { responseAs[String] shouldEqual "The form fields are color = 'blue', count = '42'" } Post("/", FormData("x" -> "1", "x" -> "5")) ~> route ~> check { responseAs[String] shouldEqual "The form fields are x = '5'" }
- Java