Module io.inverno.mod.web.client


module io.inverno.mod.web.client

The Inverno framework Web client module provides a Web enabled HTTP1.x and HTTP/2 client.

It combines Inverno HTTP discovery module and HTTP client module behind an API that abstract service resolution and service request logic. The Web client API also extends the HTTP client API with global interceptor definitions and automatic content encoding and decoding.

It defines the following sockets:

discoveryServices (required)
The list of HTTP discovery services used to resolve service URIs.
httpClient (required)
The HTTP client used to create unbound exchanges.
mediaTypeConverters (required)
The media type converters used to encode and decode payloads.
reactor (required)
The reactor providing the event loop used to refresh cached services.
configuration
The Web client module configuration.
parameterConverter
A parameter converter used to convert parameter values.

It exposes the following beans:

configuration
The Web client module configuration
webClientBoot
The Web client boot used to initialize the root Web client

A Web client can be creates and used as follows:


 List<? extends HttpDiscoveryService> discoveryServices = ... // dnsHttpDiscoveryService, configurationHttpMetaDiscoveryService...
 HttpClient httpClient = ...
 List<MediaTypeConverter<ByteBuf>> mediaTypeConverters = ...
 Reactor reactor = ...

 Client module = new Client.Builder(discoveryServices, httpClient, mediaTypeConverters, reactor).build();
 try {
     WebClient<AppContext> rootWebClient = module.webClientBoot().webClient(AppContext::new);
     String responseBody = rootWebClient
         .exchange(URI.create("http://example.org"))
         .flatMap(WebExchange::response)
         .flatMapMany(response -> response.body().string().stream())
         .collect(Collectors.joining())
         .block();
 }
 finally {
     module.stop();
 }
 
Since:
1.12
Author:
Jeremy Kuhn