Last active
March 1, 2020 15:21
-
-
Save hakuch/1cd0bdc051bf9d7e8e41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
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)
The following works for me.
r.entity.toStrict(200.millis).map(_.data.utf8String)
@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
Almost, I answered in more detail on gitter: ☝️ September 29, 2015 7:56 PM
A quick one is:
In general we encourage staying in streaming land.
I made a ticket for improving docs to explain this exact use case akka/akka#18599