diff --git a/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/FormFieldDirectivesExamplesSpec.scala b/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/FormFieldDirectivesExamplesSpec.scala index 9c2d7e3b42..438a9fdc30 100644 --- a/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/FormFieldDirectivesExamplesSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/FormFieldDirectivesExamplesSpec.scala @@ -24,5 +24,23 @@ class FormFieldDirectivesExamplesSpec extends RoutingSpec { responseAs[String] shouldEqual "Request is missing required form field 'color'" } } + "formField" in { + val route = + formField('color) { color => + complete(s"The color is '$color'") + } ~ + formField('id.as[Int]) { id => + complete(s"The id is '$id'") + } + + 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'" + } + } } diff --git a/akka-docs-dev/rst/scala/http/routing-dsl/directives/form-field-directives/formField.rst b/akka-docs-dev/rst/scala/http/routing-dsl/directives/form-field-directives/formField.rst index 73c1d91971..1aa9a32dd1 100644 --- a/akka-docs-dev/rst/scala/http/routing-dsl/directives/form-field-directives/formField.rst +++ b/akka-docs-dev/rst/scala/http/routing-dsl/directives/form-field-directives/formField.rst @@ -3,6 +3,8 @@ formField ========= +Allows extracting a single Form field sent in the request. + An alias for :ref:`-formFields-`. Signature @@ -15,3 +17,9 @@ Description ----------- See :ref:`-formFields-`. + +Example +------- + +.. includecode2:: ../../../../code/docs/http/scaladsl/server/directives/FormFieldDirectivesExamplesSpec.scala + :snippet: formField