Interface WebClient<A extends ExchangeContext>

Type Parameters:
A - the exchange context type
All Superinterfaces:
WebRouteInterceptor<A>
All Known Subinterfaces:
WebClient.Intercepted<A>

public interface WebClient<A extends ExchangeContext> extends WebRouteInterceptor<A>

A Web client for invoking HTTP services.

A Web client is backed by a caching composite DiscoveryService for resolving HTTP services from service URIs.

It allows to specify interceptors with a set of criteria applied to matching exchanges. Every time an interceptor is declared on a Web client, a new WebClient.Intercepted Web client instance is created containing the interceptor and any other interceptors declared on ancestor clients.


 WebClient<ExchangeContext> webClient = ...
 WebClient.Intercepted<ExchangeContext> interceptedWebClient = webClient.intercept()
     .method(Method.GET) // intercept all GET requests
     .interceptor(inteceptableExchange -> ...)
 

Interceptors can also be declared globally in a module in WebRouteInterceptor.Configurer beans which are injected in the module's Web client instance on initialization.

An HTTP request can be sent to any destination that can be resolved by the set of discovery services injected in the Web client module:


 WebClient<ExchangeContext> webClient = ...

 webClient.exchange(URI.create("http://example.org"))
     .map(WebExchange::response)
     ...
 

The Web client WebClient.Boot bean is exposed in the module, it is used to create the root Web client instance, it requires to specify the factory used to create the ExchangeContext for any exchange. There can be only one type for the exchange context per Web client module instance.


 WebClient.Boot boot = ...
 WebClient<Context> rootWebClient = boot.webClient(Context::new)
     .configureInterceptors(...)
     .intercept()...
 

The root WebClient thus obtained can then be used inside the module or injected in composed module. The Web compiler normally takes care of generating a wrapper bean for initializing this root Web client.

Since:
1.12
Author:
Jeremy Kuhn