extractRequestEntity
Description
Extracts the RequestEntity
RequestEntity
from the RequestContext
RequestContext
.
The directive returns a RequestEntity
RequestEntity
without unmarshalling the request. To extract domain entity, entity should be used.
Example
- Scala
-
source
val route = extractRequestEntity { entity => complete(s"Request entity content-type is ${entity.contentType}") } // tests: val httpEntity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, "req") Post("/abc", httpEntity) ~> route ~> check { responseAs[String] shouldEqual "Request entity content-type is text/plain; charset=UTF-8" }
- Java
-
source
import static org.apache.pekko.http.javadsl.server.Directives.extractRequestEntity; final Route route = extractRequestEntity( entity -> complete("Request entity content-type is " + entity.getContentType())); // tests: testRoute(route) .run( HttpRequest.POST("/abc") .withEntity(HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, "req"))) .assertEntity("Request entity content-type is text/plain; charset=UTF-8");
1.1.0+17-3b5f9b27*