In [1]:
classpath.add("com.typesafe.akka" %% "akka-http-core" % "2.4.8")


9 new artifact(s)
9 new artifacts in macro
9 new artifacts in runtime
9 new artifacts in compile


In [31]:
import akka.stream._
import akka.stream.scaladsl._
import akka.actor._
import akka.http._
import akka.http.scaladsl._
import akka.http.scaladsl.model._
import akka.util._


implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()


import akka.stream._
import akka.actor._
import akka.http._
import akka.http.scaladsl._
import akka.http.scaladsl.model._
import akka.util._
system: ActorSystem = akka://default
materializer: ActorMaterializer = ActorMaterializerImpl(akka://default,ActorMaterializerSettings(4,16,,<function1>,StreamSubscriptionTimeoutSettings(CancelTermination,5000 milliseconds),false,1000,1000,false,true),akka.dispatch.Dispatchers@e710705,Actor[akka://default/user/StreamSupervisor-4#-1670034039],false,akka.stream.impl.SeqActorNameImpl@7b90864c)

In [32]:
val now = "http://www.timeapi.org/utc/now.json"
val res = Http().singleRequest(HttpRequest(uri=now))


now: String = "http://www.timeapi.org/utc/now.json"
res: concurrent.Future[HttpResponse] = List()

In [40]:
val stream = res.value.get.get.entity.dataBytes


stream: scaladsl.Source[ByteString, Any] = Source(SourceShape(StatefulMapConcat.out), CompositeModule [4be90ada]
  Name: iterableSource
  Modules:
    (singleSource) GraphStage(SingleSource(List(ByteString(123, 34, 100, 97, 116, 101, 83, 116, 114, 105, 110, 103, 34, 58, 34, 50, 48, 49, 54, 45, 48, 56, 45, 48, 51, 84, 49, 57, 58, 49, 49, 58, 49, 55, 43, 48, 49, 58, 48, 48, 34, 125)))) [597d236b]
    (unnamed) [245b4e70] copy of GraphStage(StatefulMapConcat) [23e5748a]
  Downstreams: 
    single.out -> StatefulMapConcat.in
  Upstreams: 
    StatefulMapConcat.in -> single.out
  MatValue: Atomic(singleSource[597d236b]))

In [41]:
val sink = scaladsl.FileIO.toPath(new java.io.File("test.json").toPath)


sink: scaladsl.Sink[ByteString, concurrent.Future[IOResult]] = Sink(SinkShape(FileSink.in), FileSink(test.json, Set(WRITE, CREATE)) [22ea013e])

In [43]:
val st = stream.runWith(sink)


st: concurrent.Future[IOResult] = List()

In [44]:
st.value


res43: Option[scala.util.Try[IOResult]] = Some(Success(IOResult(42L, Success(Done))))