Akka Http Client

In Akka Http Client - User-Agent header Marcin brough up a very strangenice-looking a HTTP client code snippet that can't be disregarded while learning Spray.

val connection = Http().outgoingConnection("someServer", 443)
val request:HttpRequest = RequestBuilding.Get(s"/some/address.json")
//    I want to add header here
//    request.addHeader(HttpHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"))
Source.single(request).via(connection.flow).runWith(Sink.head).flatMap { response =>
  response.status match {
    case status if status.isSuccess =>
      val ticker = Unmarshal(response.entity).to[Ticker]
      println(ticker)
      ticker
    case status =>
      println(s"$status error:${response.toString}")
      Future.failed(new IOException(s"Token request failed with status ${response.status} and error ${response.entity}"))
  }
}

FIXME Describe the constituents.

results matching ""

    No results matching ""