Spring.io Doc
REST Clients
The Spring Framework provides the following choices for making calls to REST endpoints:
WebClient - non-blocking, reactive client w fluent API.
RestTemplate - synchronous client with template method API.
HTTP Interface - annotated interface with generated, dynamic proxy implementation.
webClient
WebClient-非阻塞、反应式客户端流畅的 API
WebClient 是一个非阻塞的反应式客户端,用于执行 HTTP 请求。它是在5.0中引入的,提供了 RestTemplate 的替代方案,支持同步、异步和流场景。
WebClient 支持以下内容:
Non-blocking I/O.
Reactive Streams back pressure.
High concurrency with fewer hardware resources.
Functional-style, fluent API that takes advantage of Java 8 lambdas.
Synchronous and asynchronous interactions.
Streaming up to or streaming down from a server.
HTTP Interface
第一,使用@HttpExchange 方法声明一个接口:
@GetExchange("/repos/{owner}/{repo}") 需要http请求的接口
Repository 是自定义实体类用来收集数据
第二,创建一个代理来执行声明的 HTTP 交换:
可以这么理解
@ HttpExchange 在适用于所有方法的类型级别得到支持: