我创建了一个使用Hammock(https://github.com/pepegar/hammock)的简单程序,现在我想从githubAPI 中获取带有 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数据映射到我的对象。但现在我也想从中得到headers,response我不能简单地做到这一点response.headers。只有当我删除.as[List[GitRepository]]线并拥有完整的HttpResponse我才能访问headers. 是否有可能在headers不解析整体的情况下获得HttpResponse?