extractDataBytes
Signature
def extractDataBytes: Directive1[Source[ByteString, Any]]
Description
Extracts the entities data bytes as Source[ByteString, Any]
from the RequestContext
.
The directive returns a stream containing the request data bytes.
Example
val route =
extractDataBytes { data ⇒
val sum = data.runFold(0) { (acc, i) ⇒ acc + i.utf8String.toInt }
onSuccess(sum) { s ⇒
complete(HttpResponse(entity = HttpEntity(s.toString)))
}
}
// tests:
val dataBytes = Source.fromIterator(() ⇒ Iterator.range(1, 10).map(x ⇒ ByteString(x.toString)))
Post("/abc", HttpEntity(ContentTypes.`text/plain(UTF-8)`, data = dataBytes)) ~> route ~> check {
responseAs[String] shouldEqual "45"
}