Reputation: 167
Using the high level routing api,
How does one complete() a request within a route using a byte array binary response,
For example:
complete(HttpResponse(entity = HttpEntity(MediaTypes.`application/octet-stream`, byteArray)
?
Thank you
Upvotes: 2
Views: 1880
Reputation: 17953
Use the Strict
entity type:
import akka.util.ByteString
import akka.http.scaladsl.model.{HttpResponse, MediaTypes,HttpEntity}
val byteArray : Array[Byte] = ???
val body = ByteString(byteArray)
val entity = HttpEntity.Strict(MediaTypes.`application/octet-stream`, body)
val httpResponse = HttpResponse(entity = entity)
complete(httpResponse)
Upvotes: 4