From afcd3e21272263d5a4b908bf9f961de665b2a7f2 Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Thu, 8 Oct 2015 16:26:29 +0200 Subject: [PATCH] +doc,htp #18496 example for formfield --- .../FormFieldDirectivesExamplesSpec.scala | 18 ++++++++++++++++++ .../form-field-directives/formField.rst | 8 ++++++++ 2 files changed, 26 insertions(+) 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