Skip to content

Spring Web Client Implementation

yan li edited this page Nov 10, 2020 · 10 revisions

Spring web client uses two types of web client implementations: Rest Template and WebClient.

WebClient

Webclient is a reactive, non-blocking solution. Reactive Programming defines the Programming with asynchronous data streams.

Backgroud of WebClient

WebClient is an interface of the Spring Web Reactive module, will replace the classic RestTemplate. Every request executes the following steps to get response:

* Creating a URL object and opening the connection
* Configuring the HTTP request
* Executing the HTTP request
* Interpretation of the HTTP response
* Converting the HTTP response into a Java object
* Exception handling

RestTemplate

RestTemplate is one of the Spring's web client implementation.

ClientHttpResponse

ClientHttpResponse must be closed. And any created resources must be freed. e.g.if we tests response, response will be closed by verify(response).

verify(response).close();

https://springframework.guru/spring-5-webclient/

https://juejin.im/post/6844903903226511367

https://springframework.guru/using-resttemplate-in-spring/

Clone this wiki locally