This documentation regards version 10.1, however the current version is 10.7.0.
formField
Signature
def formField(pdm: FieldMagnet): pdm.Out
def formField(pdm: FieldMagnet): Directive[pdm.U]
Description
Allows extracting a single Form field sent in the request. Data posted from HTML Forms is either of type application/x-www-form-urlencoded
or of type multipart/form-data
.
See formFields for an in-depth description.
Example
- Scala
-
source
val route = concat( formField('color) { color => complete(s"The color is '$color'") }, formField('id.as[Int]) { id => complete(s"The id is '$id'") } ) // tests: Post("/", FormData("color" -> "blue")) ~> route ~> check { responseAs[String] shouldEqual "The color is 'blue'" } Get("/") ~> Route.seal(route) ~> check { status shouldEqual StatusCodes.BadRequest responseAs[String] shouldEqual "Request is missing required form field 'color'" }
- Java