Add RestTemplate support for HTTP interface client

See gh-30117
This commit is contained in:
Olga MaciaszekSharma
2023-07-06 19:07:40 +02:00
committed by rstoyanchev
parent bf82ed7186
commit 268f3c853e
21 changed files with 1272 additions and 227 deletions

View File

@@ -382,12 +382,24 @@ One, declare an interface with `@HttpExchange` methods:
}
----
Two, create a proxy that will perform the declared HTTP exchanges:
Two, create a proxy that will perform the declared HTTP exchanges,
either using `WebClient`:
[source,java,indent=0,subs="verbatim,quotes"]
----
WebClient client = WebClient.builder().baseUrl("https://api.github.com/").build();
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder().exchangeAdapter(WebClientAdapter.forClient(webClient)).build();
RepositoryService service = factory.createClient(RepositoryService.class);
----
or using `RestTemplate`:
[source,java,indent=0,subs="verbatim,quotes"]
----
RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory("https://api.github.com/"));
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder().exchangeAdapter(RestTemplateAdapter.forTemplate(restTemplate)).build();
RepositoryService service = factory.createClient(RepositoryService.class);
----