2017-10-14 01:24:33 +08:00
|
|
|
[[webmvc-client]]
|
|
|
|
= REST Clients
|
|
|
|
|
|
|
|
This section describes options for client-side access to REST endpoints.
|
|
|
|
|
2017-10-19 02:24:17 +08:00
|
|
|
|
|
|
|
|
2018-10-25 21:15:58 +08:00
|
|
|
|
2017-10-14 01:24:33 +08:00
|
|
|
[[webmvc-resttemplate]]
|
2018-10-06 03:54:38 +08:00
|
|
|
== `RestTemplate`
|
2017-10-14 01:24:33 +08:00
|
|
|
|
2018-07-27 20:32:59 +08:00
|
|
|
`RestTemplate` is a synchronous client to perform HTTP requests. It is the original
|
2018-09-17 22:36:43 +08:00
|
|
|
Spring REST client and exposes a simple, template-method API over underlying HTTP client
|
2018-07-27 20:32:59 +08:00
|
|
|
libraries.
|
2017-10-14 01:24:33 +08:00
|
|
|
|
2022-05-09 16:49:28 +08:00
|
|
|
NOTE: As of 5.0 the `RestTemplate` is in maintenance mode, with only requests for minor
|
|
|
|
changes and bugs to be accepted. Please, consider using the
|
2023-04-19 23:26:17 +08:00
|
|
|
xref:web/webflux-webclient.adoc[WebClient] which offers a more modern API and
|
2020-02-11 22:01:21 +08:00
|
|
|
supports sync, async, and streaming scenarios.
|
2017-10-14 01:24:33 +08:00
|
|
|
|
2023-04-19 23:26:17 +08:00
|
|
|
See xref:integration/rest-clients.adoc[REST Endpoints] for details.
|
2017-10-14 01:24:33 +08:00
|
|
|
|
2017-10-19 02:24:17 +08:00
|
|
|
|
|
|
|
|
2018-10-25 21:15:58 +08:00
|
|
|
|
2017-10-14 01:24:33 +08:00
|
|
|
[[webmvc-webclient]]
|
2018-10-06 03:54:38 +08:00
|
|
|
== `WebClient`
|
2017-10-14 01:24:33 +08:00
|
|
|
|
2018-07-27 20:32:59 +08:00
|
|
|
`WebClient` is a non-blocking, reactive client to perform HTTP requests. It was
|
2018-09-17 22:36:43 +08:00
|
|
|
introduced in 5.0 and offers a modern alternative to the `RestTemplate`, with efficient
|
2018-07-27 20:32:59 +08:00
|
|
|
support for both synchronous and asynchronous, as well as streaming scenarios.
|
2017-10-14 01:24:33 +08:00
|
|
|
|
2018-09-17 22:36:43 +08:00
|
|
|
In contrast to `RestTemplate`, `WebClient` supports the following:
|
2018-08-14 20:48:14 +08:00
|
|
|
|
|
|
|
* Non-blocking I/O.
|
|
|
|
* Reactive Streams back pressure.
|
2018-09-17 22:36:43 +08:00
|
|
|
* High concurrency with fewer hardware resources.
|
|
|
|
* Functional-style, fluent API that takes advantage of Java 8 lambdas.
|
2018-08-14 20:48:14 +08:00
|
|
|
* Synchronous and asynchronous interactions.
|
|
|
|
* Streaming up to or streaming down from a server.
|
|
|
|
|
2023-04-19 23:26:17 +08:00
|
|
|
See xref:web/webflux-webclient.adoc[WebClient] for more details.
|
2022-05-09 16:49:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[webmvc-http-interface]]
|
|
|
|
== HTTP Interface
|
|
|
|
|
|
|
|
The Spring Frameworks lets you define an HTTP service as a Java interface with HTTP
|
|
|
|
exchange methods. You can then generate a proxy that implements this interface and
|
|
|
|
performs the exchanges. This helps to simplify HTTP remote access and provides additional
|
|
|
|
flexibility for to choose an API style such as synchronous or reactive.
|
|
|
|
|
2023-04-19 23:26:17 +08:00
|
|
|
See xref:integration/rest-clients.adoc#rest-http-interface[REST Endpoints] for details.
|