query
Matches requests with HTTP method QUERY (RFC 10008).
Description
This directive filters the incoming request by its HTTP method. Only requests with method QUERY are passed on to the inner route. All others are rejected with a MethodRejectionMethodRejection, which is translated into a 405 Method Not Allowed response by the default RejectionHandler.
The QUERY method is defined in RFC 10008. It is a safe and idempotent method that requests the target resource to process the enclosed content and respond with the result. Unlike GET, the QUERY method expects a request body containing the query payload.
Example
- Scala
-
source
val route = query { complete("This is a QUERY request.") } // tests: HttpRequest(method = HttpMethods.QUERY, uri = "/") ~> route ~> check { responseAs[String] shouldEqual "This is a QUERY request." } - Java
-
source
import static org.apache.pekko.http.javadsl.server.Directives.complete; import static org.apache.pekko.http.javadsl.server.Directives.query; final Route route = query(() -> complete("This is a QUERY request.")); testRoute(route) .run(HttpRequest.QUERY("/").withEntity("query content")) .assertEntity("This is a QUERY request.");
2.0.0-M2