formFieldSeq

formFieldSeq

Signature

Description

Extracts all HTTP form fields at once in the original order as (name, value) tuples of type (String, String).

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

See formFields for an in-depth description.

Warning

The directive reads all incoming HTT form fields without any configured upper bound. It means, that requests with form fields holding significant amount of data (ie. during a file upload) can cause performance issues or even an OutOfMemoryError s.

Example

val route =
  formFieldSeq { 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" -> "23", "x" -> "4", "x" -> "89")) ~> route ~> check {
  responseAs[String] shouldEqual "The form fields are x = '23', x = '4', x = '89'"
}

Contents