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

Avoid requiring uri("") when using Web(Test)Client baseUrl [SPR-15695] #20254

Closed
spring-issuemaster opened this issue Jun 23, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jun 23, 2017

Sébastien Deleuze opened SPR-15695 and commented

Currently it is currently required to write code like client.get().uri("").retrieve().bodyToMono() in order to use the baseUrl defined via the WebClient or WebTestClient instances. It would be nice to provide a solution that does not require writing uri("") (maybe client.get().retrieve().bodyToMono() but this is not trivial with current API design).


Referenced from: commits 5f2d2b2, 3232cb6

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 4, 2017

Arjen Poutsma commented

I've pushed a branch containing a fix for this issue. See https://github.com/poutsma/spring-framework/blob/2915bba2e07083f2c6d9c1a2b0e85189773dcbcf/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java
Before I continue down this path, i.e. do the same for WebTestClient, I would like to get some confirmation for the approach taken.

The basic idea of my fix is that the HTTP method methods in WebClient (get, post, etc.) should be able to "bypass" the uri stage, and skip straight to defining headers, or even doing an exchange or retrieve (i.e. call methods on RequestHeaderSpec or RequestBodySpec.

I have accomplished this by adding two new composed interfaces: RequestHeadersUriSpec and RequestBodyUriSpec. RequestHeadersUriSpec extends from the existing UriSpec and RequestHeaderSpec, while RequestBodyUriSpec extends from UriSpec and RequestBodySpec. These types are returned from the HTTP methods (get, post etc). The uri methods on these types return a plain RequestHeaderSpec and RequestBodySpec (i.e. types without the uri methods), so that you can call uri once only.

While the resulting code works, and gets the desired effect; it does make the relationship between WebClient's internal types more complex. The question we have to answer is whether this complexity is wort it. I personally think it is: the internal types are there to facilitate the DSL, they are not really meant for standalone consumption. And it does solve the uri("") problem that I have seen a lot in Pivotal demos already, and just looks weird.

What do you think, Rossen Stoyanchev, Sébastien Deleuze Juergen Hoeller?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 6, 2017

Arjen Poutsma commented

The approach described above was approved on today's meeting.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 7, 2017

Arjen Poutsma commented

Implemented in 3232cb6 and 5f2d2b2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.