13 January 2022 - Easily log the Request and Response of a Microprofile REST Client
Using the Microprofile REST Client makes life significantly easier when you’re having to call a REST API, if you aren’t using them already I’d definitely consider adopting them.
The biggest drawback is that it’s not always clear exactly what they’re doing, because the framework handles the majority of the work for you, it’s not as simple as just logging the entity to see what the response looks like because your logger could output the entity in a different way to the one used by the REST Client.
Luckily for us, we can easily register a LoggingFeature that will automatically log the Headers, Request and Response details for each request made. Hurrah! This is really simple and straightforward whilst being especially useful for development and debugging.
Read on to find out more!
TL;DR:- You can register the Jersey LoggingFeature with the REST Client, and it will log Request and Response content out of the box. You can even alter the output to log headers only or everything.