我已经创建了一个使用Hammock(https://github.com/pepegar/hammock)的简单程序,现在我想从github应用程序接口中获得reposne的报头的响应。我创建了一个这样的代码:
object GitHttpClient extends App {
implicit val decoder = jsonOf[IO, List[GitRepository]]
implicit val interpreter = ApacheInterpreter.instance[IO]
val response = Hammock
.request(Method.GET, uri"https://api.github.com/orgs/github/repos?per_page=3", Map())
.as[List[GitRepository]]
.exec[IO]
.unsafeRunSync()
println(response)
}
case class GitRepository(full_name: String, contributors_url: String)它工作得很好,我将Git数据映射到我的对象上。但现在我也想从response获取headers,而不能通过简单的response.headers来实现。只有当我删除.as[List[GitRepository]]行并拥有整个HttpResponse时,我才能访问headers。有可能在不解析整个HttpResponse的情况下获得headers吗
发布于 2019-11-10 21:32:48
我在收到响应后使用Decoder解决了这个问题:
val response = Hammock
.request(Method.GET, uri"https://api.github.com/orgs/github/repos?per_page=3", Map())
.exec[IO]
.unsafeRunSync()
println(response.headers("Link") contains ("next"))
println(HammockDecoder[List[GitRepository]].decode(response.entity))https://stackoverflow.com/questions/58788832
复制相似问题