Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update retrieve() in RestClient to execute and extract in single scope #33777

Closed
rstoyanchev opened this issue Oct 23, 2024 · 7 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Oct 23, 2024

The retrieve() workflow in RestClient splits the exchange over two method calls. The call to retrieve() executes the request but doesn't extract, and the subsequent call to one of the ResponseSpec methods actually extracts the response.

This makes sense but it's also reasonable to conclude you can just call retrieve() if you don't care for the response. In that case, however, the observation scope remains open, the status is not checked, and the connection is not closed.

retrieve() should merely a step towards fully declaring the exchange before, and only once a ResponseSpec method is selected should we proceed with execution and response extraction. Same way it works with the RestTemplate.

This will make the retrieve() workflow a true shortcut for calling exchange(), fully scoped within a call to exchange() with a built-in ExchangeFunction based on the ResponseSpec selection. If an application actually wants to split execution and extraction into separate steps, it can use the exchange variants.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Oct 23, 2024
@rstoyanchev rstoyanchev added this to the 6.2.0-RC3 milestone Oct 23, 2024
@rstoyanchev rstoyanchev self-assigned this Oct 23, 2024
@fmasa
Copy link

fmasa commented Nov 29, 2024

Could this behavior change be mentioned in the changelog? 🙏

@bclozel
Copy link
Member

bclozel commented Nov 29, 2024

@fmasa can you elaborate which behavior change surprised you while upgrading?

@fmasa
Copy link

fmasa commented Nov 29, 2024

@bclozel The 6.2.0 changed the behavior of retrieve. Previously it actually executed the HTTP request but now it does not (and the needs to call ResponseSpec.

We had one fire&forget request that stopped being called after upgrading to Spring 6.2.0 and when going through release notes I did not find any mention of this. 🙂

@bclozel
Copy link
Member

bclozel commented Nov 29, 2024

Thanks, I'll add a note in the release notes. Out of curiosity: we added an annotation to warn people about this in #33818. IDEs should highlight this on your screen. Does it work for you?

I know this doesn't replace a warning in the release notes but just wanted to make sure this shows for future usages.

@fmasa
Copy link

fmasa commented Nov 29, 2024

@bclozel Thanks a lot 🙇

@fmasa
Copy link

fmasa commented Nov 29, 2024

For the annotation: I don't see anything in IDEA. But quick search shows that it's not supported there yet?.

We also use detekt which catches that 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants