Skip to content

Instantly share code, notes, and snippets.

@hakuch
Last active March 1, 2020 15:21
Show Gist options
  • Save hakuch/1cd0bdc051bf9d7e8e41 to your computer and use it in GitHub Desktop.
Save hakuch/1cd0bdc051bf9d7e8e41 to your computer and use it in GitHub Desktop.
import akka.http.scaladsl.model._
import akka.stream._
import scala.concurrent.duration._
import scala.concurrent._
object Http {
def responseBodyAsString(r: HttpResponse)(implicit m: Materializer): String =
Await.result(
r.entity.dataBytes.runWith(Sink.head).map(_.utf8String),
Duration.Inf)
}
@pete-proton
Copy link

@ktoso could you have a look at the query below. have the same question. thanks in advance.

toStrict doesn't seem to have the dataBytes method. I am getting compilation error there. Please suggest if I am doing anything wrong.

def responseBodyAsString(r: HttpResponse)(implicit m: Materializer): String =
    Await.result(
      r.entity.toStrict(200.millis).dataBytes.runWith(Sink.head).map(_.utf8String),Duration.Inf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment