1

我正在玩 Akka Http 客户端。我已经创建了一个简单的请求,但是如何解组响应?在服务器端很容易使用 circe 来编组响应,但我在客户端有困难

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.Uri.Query
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.Materializer

import scala.concurrent.ExecutionContext


class QuestionsFetcher {

  import de.heikoseeberger.akkahttpcirce.CirceSupport._
  import io.circe.generic.auto._

  val baseUrl = "https://somewhere.com"


 def fetch(tag: String)(implicit ac: ActorSystem, materializer: Materializer) = {

implicit val ec: ExecutionContext = ac.dispatcher

val fromDate = DateTime.now.minus(1000 * 60 * 60 * 24)
val uri = Uri(baseUrl).withQuery(Query("order"->"desc"))
val request = HttpRequest(HttpMethods.GET, uri)

Http().singleRequest(request)
    .map(r => Unmarshal(r.entity.withContentType(ContentTypes.`application/json`)).to[Items])

} }

运行代码时出现 ErrorFuture(io.circe.ParsingFailure: expected json value got (line 1, column 1))

4

1 回答 1

0

内容已压缩 - 所以在运行解码器流程之后就可以了

于 2017-01-13T12:14:14.697 回答