In our project, we need to pass a certain header information in all the REST calls that are sent out to other internal APIs.
One way is to change all the hundreds or even thousands of REST invocations to add this mapping before the REST call is initiated.
But, I was wondering if there is a smarter way of doing this using aspects/filters/listeners/interceptors in Spring/Java?
Example: If I make a call from REST API 1 to an endpoint, I am trying to explore a way to intercept the constructed HTTP request and add the header and fire the request.
Any suggestions about solving or any other good practices are welcome.
Thank you.
For any person who stumbles upon this post in the future, here is what it took to make it working.
Implement a class that 'implements' ClientHttpRequestInterceptor. The method that needs to be overridden is where you can catch the request headers and modify them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With