user1661898
user1661898

Reputation: 167

Akka Http Server - How to have route respond with byte array binary response

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

Answers (1)

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

Related Questions