Skip to content

Commit cfe2db0

Browse files
committed
Improve reference docs on RestClient.retrieve()
As of Spring Framework 6.2, the `RestClient.retrieve()` method is a no-op and developers must invoke a terminal operation on the returned `ResponseSpec` to have any side effect. This has been documented in the Javadoc and the wiki release notes, but this commit highlights this as well in the reference documentation. Closes gh-34334
1 parent 53afe27 commit cfe2db0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

framework-docs/modules/ROOT/pages/integration/rest-clients.adoc

+7-3
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ Finally, the body can be set to a callback function that writes to an `OutputStr
115115

116116
==== Retrieving the response
117117

118-
Once the request has been set up, the HTTP response is accessed by invoking `retrieve()`.
119-
The response body can be accessed by using `body(Class)` or `body(ParameterizedTypeReference)` for parameterized types like lists.
118+
Once the request has been set up, it can be sent by chaining method calls after `retrieve()`.
119+
For example, the response body can be accessed by using `retrieve().body(Class)` or `retrieve().body(ParameterizedTypeReference)` for parameterized types like lists.
120120
The `body` method converts the response contents into various types – for instance, bytes can be converted into a `String`, JSON can be converted into objects using Jackson, and so on (see <<rest-message-conversion>>).
121121

122-
The response can also be converted into a `ResponseEntity`, giving access to the response headers as well as the body.
122+
The response can also be converted into a `ResponseEntity`, giving access to the response headers as well as the body, with `retrieve().toEntity(Class)`
123+
124+
NOTE: Calling `retrieve()` by itself is a no-op and returns a `ResponseSpec`.
125+
Applications must invoke a terminal operation on the `ResponseSpec` to have any side effect.
126+
If consuming the response has no interest for your use case, you can use `retrieve().toBodilessEntity()`.
123127

124128
This sample shows how `RestClient` can be used to perform a simple `GET` request.
125129

0 commit comments

Comments
 (0)