Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DevonPeroutky opened this issue Nov 27, 2018 · 2 comments

Comments

@DevonPeroutky
Copy link

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
Copy link
Author

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

@pepegar
Copy link
Owner

pepegar commented Jan 9, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants