hammock
hammock copied to clipboard
Documentation Request: How to consume response and headers in one request.
The docs make it pretty clear how to make a request and decode the entity of the HttpResponse:
val response = Hammock
.request(Method.GET, uri"https://api.fidesmo.com/apps", Map())
.as[List[String]]
.exec[IO]
And you can get the headers like:
val response = Hammock
.request(Method.GET, uri"https://api.fidesmo.com/apps", Map())
.map(_.headers)
.as[List[String]]
.exec[IO]
But how could one decode the response and consume the headers and body into a case class like:
case class BodyAndHeaders[T](body: T, responseHeaders: Map[String, String])
I guess this question, more specifically, is how to decode an Entity
to a case class via Circe.
Hey Devon! sorry for the late response...
Decoding an entity to a case class via circe can be done with the hammock-circe
module. You can see an example here https://scastie.scala-lang.org/F5wqP0yNRTiDQPa73lQL4w
As per getting the headers map, you can get them from the HttpResponse
directly (response.headers
)