def consumeResponseContent()

in app/services/HttpHelpers.scala [19:39]


  def consumeResponseContent(response:HttpResponse)(implicit mat:Materializer, ec:ExecutionContext) =
    response
      .entity
      .dataBytes
      .toMat(Sink.reduce[ByteString]((acc, elem)=>acc.concat(elem)))(Keep.right)
      .run()


  /**
   * unmarshals content from `consumeResponseContent` to an object of the type given by O.
   * takes in a Future to make composition easier.
   * @param from a Future containing a ByteString of json content, from `consumeResponseContent`
   * @tparam O the data type to marshal out to
   * @return either a Right with the object or a Left containing a decoding error.
   */
  def unmarshalContent[O:io.circe.Decoder](from:Future[ByteString])(implicit ec:ExecutionContext) =
    from.map(bytes=>{
      val stringContent = bytes.utf8String
      logger.debug(s"Server response was $stringContent")
      io.circe.parser.parse(bytes.utf8String).flatMap(_.as[O])
    })