# 2. REST客户端

本节描述了客户端对REST端点的访问选项。

## 2.1 RestTemplate

RestTemplate是执行HTTP请求的同步客户端。它是原始的Spring REST客户端，并且在基础HTTP客户端库上公开了简单的模板方法API。

> 从5.0开始，无阻塞，反应式WebClient提供了RestTemplate的现代替代方案，并有效支持同步和异步以及流方案。 RestTemplate将在将来的版本中弃用，并且以后将不会添加主要的新功能。

有关详细信息，请参见REST端点。

## 2.2 WebClient

WebClient是执行HTTP请求的非阻塞，反应式客户端。它是在5.0中引入的，它提供了RestTemplate的现代替代方案，并有效支持同步和异步以及流方案。

与RestTemplate相比，WebClient支持以下内容：

* 非阻塞I / O。
* 反应性产生背压。
* 高并发，硬件资源更少。
* 利用Java 8 lambda的功能风格，流畅的API。
* 同步和异步交互。
* 从服务器流向上或从服务器向下流。

有关更多详细信息，请参见WebClient。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flydean.com/spring-framework-documentation5/webservlet/2.rest-clients.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
