I was pretty much excited to leverage RestClient Library for microservice communications. Basic Use Cases are working but real time use case such as bearer authorization token propagation from client to keycloak/gateway component not able to implement due to limitation in RestClientBuilder Api . In contrast WebClientBuilder supports most of all functionalities in fluent Api Approach some of them are (Filter, Codecs and ExchangeStrategies)
The Filter unavailability is causing hindrance to test different microservices communication due to absence of valid token in request header
Eg; snippet for WebClientBuilder
builder
.clone()
**.clientConnector(HttpClient Object)**
**.codec(HTTP message readers and writers)**
**.filter(errorHandler())**
**.filter(new ServletBearerExchangeFilterFunction())**
.baseUrl("abc.com")
.build();
Really Hoping for inclusion of these functionalities in RestClient which makes it whole dealing with Inter Microservices communication
Comment From: poutsma
The WebClient
is a reactive HTTP client, and uses reactive components like filters, codecs, and exchange strategies. They all have reactive methods signatures (Flux, Mono).
The RestClient
(and before it the RestTemplate
) use non-reactive components to achieve the same goal. For instance, the non-reactive counterpart to codecs are HttpMessageConverter
s, and the non-reactive counterpart for a filter is the ClientHttpRequestInterceptor
or ClientHttpRequestInitializer
if you only need headers.
In summary: RestClient
has similar configuration capabilities as WebClient
, but the components are named differently. Supporting reactive components—introduced for WebClient
—in RestClient
therefore is undesirable, as it would lead to duplication.