Henri Cook
Henri Cook's Blog

Henri Cook's Blog

Http4s: Tips and Tricks

Http4s: Tips and Tricks

Henri Cook's photo
Henri Cook

Published on Jan 1, 2021

1 min read

Get the text body of a response with EntityDecoder

If you've got a request like this:

val postRequest: Task[Request[Task]] = POST(
                                     payload,
                                     uri
                                   )

and you just want the body as text (e.g. for debug), use:

postRequest.map { req =>
  client.run(req).use {
    case Status.Successful(resp) =>
      EntityDecoder.decodeText(resp).flatMap { respText =>
        logger.info(s"The body of the response as text is: " + respText)
      }
  }
}
 
Share this