spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.21k stars 37.97k forks source link

WebFlux equivalent of MvcUriComponentsBuilder [SPR-15953] #20505

Open spring-projects-issues opened 7 years ago

spring-projects-issues commented 7 years ago

Arjen Poutsma opened SPR-15953 and commented

We could use a WebFluxUriComponentsBuilder that has similar functionality as the ServletUriComponentsBuilder,

An additional method that WebFluxUriComponentsBuilder should have is fromServerRequest, taking a ServerRequest from WebFlux.fn, as that type does not implement HttpRequest, and therefore cannot be used with UriComponentsBuilder.fromHttpRequest.


Issue Links:

Referenced from: commits https://github.com/spring-projects/spring-framework/commit/1a3cc3df94c0f8e504f36e9be8e6f2ded5a12750, https://github.com/spring-projects/spring-framework/commit/a7617a264120ca486d7c92bb4255ec1ac3ef986e

spring-projects-issues commented 7 years ago

Rossen Stoyanchev commented

ServerRequestUriComponentsBuilder has methods to build from a request instance. Considering that UriComponentsBuilder.fromHttpRequest already exists what else would WebFluxUriComponentsBuilder have besides a fromServerRequest(ServerRequest) method?

Note that we will also need an equivalent of MvcUriComponentsBuilder where the name WebFluxUriComponentsBuilder would be a good fit.

spring-projects-issues commented 7 years ago

Rossen Stoyanchev commented

An alternative idea is something like ServerRequest.relativeToRequestUri returning UriComponentsBuilder.

spring-projects-issues commented 7 years ago

Arjen Poutsma commented

Initial version committed at https://github.com/spring-projects/spring-framework/commit/a7617a264120ca486d7c92bb4255ec1ac3ef986e.

As discussed, Rossen Stoyanchev will add subsequent @Controller-related methods.

spring-projects-issues commented 6 years ago

Rossen Stoyanchev commented

Arjen Poutsma taking a quick look, for WebFluxUriComponentsBuilder to have @Controller methods its current location could be an issue. MvcUriComponentsBuilder by comparison in is in the same package as all the other annotation related classes. Even if we don't run into circular dependencies, arguably such a builder should be in the annotations package. Also I can't imagine that using such a WebFluxUriComponentsBuilder from the functional framework -- with a ton of @Controller methods and only 1 for ServerRequest, is ideal.

Since what is needed for ServerRequest is a trivial one-liner, could we find another solution perhaps? ServerRequest has a uri() method. What about a uriComponentsBuilder next to it?

spring-projects-issues commented 6 years ago

Arjen Poutsma commented

??Since what is needed for ServerRequest is a trivial one-liner, could we find another solution perhaps? ServerRequest has a uri() method. What about a uriComponentsBuilder next to it???

That sounds like a good idea. I will move the method from WebFluxUriComponentsBuilder to ServerRequest, and remove WebFluxUriComponentsBuilder altogether.

spring-projects-issues commented 6 years ago

Arjen Poutsma commented

Done, see https://github.com/spring-projects/spring-framework/commit/1a3cc3df94c0f8e504f36e9be8e6f2ded5a12750

spring-projects-issues commented 6 years ago

Rossen Stoyanchev commented

Now that ServerRequest has an option and #20546 adds the same controllers methods, this is less critical for 5.0 GA. I'm postponing for 5.1.

poutsma commented 5 years ago

Closing, as I don't think we need this anymore.

gregturn commented 5 years ago

Spring HATEOAS, which is currently coding reactor support, could use it.

treuherz commented 5 years ago

Without this functionality, is there any way to generate URIs based on controller methods? From @poutsma's comment I assumed the functionality of MvcUriComponentsBuilder would be replicated by the additions that were made in bdde0f1 and 1a3cc3d, but it doesn't seem that way. If a UriComponentsBuilder is injected as an argument to a handler method, there is still no reliable way to construct a link with that to another method on a controller, the way MvcUriComponentsBuilder#fromMethod does.