Interface WebClient<A extends ExchangeContext>
- Type Parameters:
A
- the exchange context type
- All Superinterfaces:
WebRouteInterceptor<A>
- All Known Subinterfaces:
WebClient.Intercepted<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
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Web client boot used that initializes the root Web client.static interface
WebClient.Intercepted<A extends ExchangeContext>
An intercepted Web client.static interface
WebClient.WebExchangeBuilder<A extends ExchangeContext>
A Web exchange builder.Nested classes/interfaces inherited from interface io.inverno.mod.web.client.WebRouteInterceptor
WebRouteInterceptor.Configurer<A extends ExchangeContext>
-
Method Summary
Modifier and TypeMethodDescriptionconfigureInterceptors
(WebRouteInterceptor.Configurer<? super A> configurer) Configures multiple Web route interceptors.configureInterceptors
(List<WebRouteInterceptor.Configurer<? super A>> configurers) Configures multiple Web route interceptors.Mono
<WebExchange<A>> Creates a Web exchange.Creates a Web exchange builder.default Mono
<WebExchange<A>> Creates a Web exchange.Returns a new interceptor manager for defining a Web route interceptor.default WebClient.Intercepted
<A> intercept
(Function<WebRouteInterceptorManager<A, ? extends WebRouteInterceptor<A>>, ? extends WebRouteInterceptor<A>> configurer) Configures a Web route interceptor.
-
Method Details
-
intercept
WebRouteInterceptorManager<A,WebClient.Intercepted<A>> intercept()Description copied from interface:WebRouteInterceptor
Returns a new interceptor manager for defining a Web route interceptor.
- Specified by:
intercept
in interfaceWebRouteInterceptor<A extends ExchangeContext>
- Returns:
- a new Web route interceptor manager
-
intercept
default WebClient.Intercepted<A> intercept(Function<WebRouteInterceptorManager<A, ? extends WebRouteInterceptor<A>>, ? extends WebRouteInterceptor<A>> configurer) Description copied from interface:WebRouteInterceptor
Configures a Web route interceptor.
The result returned by the specified configurer function must be the Web route interceptor returned by the input interceptor manager after defining the interceptor and which contains the configured interceptor. If that requirement is not met, invoking this method will most likely result in a no-op operation since the resulting intercepted Web client instance would be lost.
- Specified by:
intercept
in interfaceWebRouteInterceptor<A extends ExchangeContext>
- Parameters:
configurer
- a Web route interceptor configurer function- Returns:
- the Web route interceptor containing the configured interceptor
-
configureInterceptors
WebClient.Intercepted<A> configureInterceptors(WebRouteInterceptor.Configurer<? super A> configurer) Description copied from interface:WebRouteInterceptor
Configures multiple Web route interceptors.
- Specified by:
configureInterceptors
in interfaceWebRouteInterceptor<A extends ExchangeContext>
- Parameters:
configurer
- a Web route interceptor configurer- Returns:
- the Web route interceptor containing the configured interceptors
-
configureInterceptors
WebClient.Intercepted<A> configureInterceptors(List<WebRouteInterceptor.Configurer<? super A>> configurers) Description copied from interface:WebRouteInterceptor
Configures multiple Web route interceptors.
- Specified by:
configureInterceptors
in interfaceWebRouteInterceptor<A extends ExchangeContext>
- Parameters:
configurers
- a list of Web route interceptor configurers- Returns:
- the Web route interceptor containing the configured interceptors
-
exchange
Creates a Web exchange.
This method is a shortcut for
exchange(Method.GET, uri)
.- Parameters:
uri
- the service URI- Returns:
- a
Mono
emitting the Web exchange - Throws:
IllegalArgumentException
- if the specified URI is not a valid service URI
-
exchange
Creates a Web exchange.
- Parameters:
method
- the HTTP methoduri
- the service URI- Returns:
- a
Mono
emitting the Web exchange - Throws:
IllegalArgumentException
- if the specified URI is not a valid service URI
-
exchange
Creates a Web exchange builder.
- Parameters:
uri
- a service URI- Returns:
- a Web exchange builder
- Throws:
IllegalArgumentException
- if the specified URI is not a valid service URI
-