+doc,htp #18496 overrideMethodWithParameter

This commit is contained in:
Konrad Malawski 2015-10-08 16:26:29 +02:00
parent 9edffd0930
commit ce07ae75b7
8 changed files with 38 additions and 70 deletions

View file

@ -99,4 +99,28 @@ class MethodDirectivesExamplesSpec extends RoutingSpec {
responseAs[String] shouldEqual "This HEAD request, clearly is not a GET!"
}
}
}
"overrideMethodWithParameter-0" in {
val route =
overrideMethodWithParameter("method") {
get {
complete("This looks like a GET request.")
} ~
post {
complete("This looks like a POST request.")
}
}
Get("/?method=POST") ~> route ~> check {
responseAs[String] shouldEqual "This looks like a POST request."
}
Post("/?method=get") ~> route ~> check {
responseAs[String] shouldEqual "This looks like a GET request."
}
Get("/?method=hallo") ~> route ~> check {
status shouldEqual StatusCodes.NotImplemented
}
}
}

View file

@ -5,10 +5,7 @@
package docs.http.scaladsl.server
package directives
import akka.http.scaladsl.server.UnacceptedResponseContentTypeRejection
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers._
import headers._
class RespondWithDirectivesExamplesSpec extends RoutingSpec {
@ -130,18 +127,4 @@ class RespondWithDirectivesExamplesSpec extends RoutingSpec {
// }
// }
// FIXME https://github.com/akka/akka/issues/18626
// "respondWithStatus-examples" in {
// val route =
// path("foo") {
// respondWithStatus(201) {
// complete("beep")
// }
// }
//
// Get("/foo") ~> route ~> check {
// status shouldEqual StatusCodes.Created
// responseAs[String] shouldEqual "beep"
// }
// }
}
}

View file

@ -139,7 +139,6 @@ Directive Description
``PartialFunction[HttpHeader, T]``
:ref:`-options-` Rejects all non-OPTIONS requests
:ref:`-overrideMethodWithParameter-` Changes the request method to the value of the specified query parameter
:ref:`-overrideStatusCode-` Overrides the response status code with the given one
:ref:`-parameter-` Extracts a query parameter value from the request
:ref:`-parameterMap-` Extracts the request's query parameters as a ``Map[String, String]``
:ref:`-parameterMultiMap-` Extracts the request's query parameters as a ``Map[String, List[String]]``

View file

@ -3,7 +3,7 @@
overrideMethodWithParameter
===========================
...
Changes the request method to the value of the specified query parameter.
Signature
---------
@ -14,10 +14,19 @@ Signature
Description
-----------
...
Changes the HTTP method of the request to the value of the specified query string parameter.
If the query string parameter is not specified this directive has no effect.
If the query string is specified as something that is not a HTTP method,
then this directive completes the request with a ``501 Not Implemented`` response.
This directive is useful for:
- Use in combination with JSONP (JSONP only supports GET)
- Supporting older browsers that lack support for certain HTTP methods. E.g. IE8 does not support PATCH
Example
-------
.. includecode2:: ../../../../code/docs/http/scaladsl/server/directives/MethodDirectivesExamplesSpec.scala
:snippet: 0overrideMethodWithParameter
:snippet: overrideMethodWithParameter-0

View file

@ -6,7 +6,6 @@ RespondWithDirectives
.. toctree::
:maxdepth: 1
overrideStatusCode
respondWithDefaultHeader
respondWithDefaultHeaders
respondWithHeader

View file

@ -1,27 +0,0 @@
.. _-overrideStatusCode-:
overrideStatusCode
==================
Overrides the status code of all responses coming back from its inner route with the given one.
Signature
---------
.. includecode2:: /../../akka-http/src/main/scala/akka/http/scaladsl/server/directives/RespondWithDirectives.scala
:snippet: overrideStatusCode
Description
-----------
This directive transforms ``HttpResponse`` and ``ChunkedResponseStart`` messages coming back from its inner route by
unconditionally overriding the status code with the given one.
Example
-------
.. includecode2:: ../../../../code/docs/http/scaladsl/server/directives/RespondWithDirectivesExamplesSpec.scala
:snippet: overrideStatusCode-examples