hammock icon indicating copy to clipboard operation
hammock copied to clipboard

Documentation Request: How to consume response and headers in one request.

Open DevonPeroutky opened this issue 6 years ago • 2 comments

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])

DevonPeroutky avatar Nov 27 '18 01:11 DevonPeroutky

I guess this question, more specifically, is how to decode an Entity to a case class via Circe.

DevonPeroutky avatar Nov 27 '18 02:11 DevonPeroutky

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)

pepegar avatar Jan 09 '19 11:01 pepegar