Skip to content

Add Spring WebFlux support #728

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

Closed
daggerok opened this issue Jul 7, 2018 · 12 comments
Closed

Add Spring WebFlux support #728

daggerok opened this issue Jul 7, 2018 · 12 comments

Comments

@daggerok
Copy link

daggerok commented Jul 7, 2018

Hello,

Are there any options for spring-webflux functional routes?


Regards,
Maksim

@gregturn
Copy link
Contributor

There is no WebFlux support at this point in time.

@daggerok
Copy link
Author

daggerok commented Jul 12, 2018

And it's sad, at the moment I have to do some ugly weird stuff like:

  @Bean
  fun routes() = router {
    "/".nest {
      // ...
      GET("/**") {
        val url = it.uri().toURL()
        val baseURL = "${url.protocol}://${url.authority}"
        ok().body(mapOf(
            "_links" to listOf(
                mapOf(
                    "rel" to "search",
                    "href" to "$baseURL/api/search?query={searchQuery}",
                    "templated" to true
                ),
                mapOf(
                    "rel" to "details",
                    "href" to "$baseURL/api/details/{userId}",
                    "templated" to true
                ),
                mapOf(
                    "rel" to "_self",
                    "href" to url,
                    "templated" to false
                )
            )
        ).toMono())
      }
    }
  }

Thanks to Kotlin it's not so verbose, but things get worst by using java... In this case some additional code needed to wrap it in some links builder..

It would be nice to have at least some filter which could be configured and used like so:

  @Bean
  fun routes() = router {
    "/".nest {
      // ...
      GET("/**") {
       // ..
      }
    }
  }.filter { request, next -> hateoasFilter(request, next) }

Regards,
Maksim Kostromin

@ghilainm
Copy link

ghilainm commented Jan 8, 2019

@gregturn Any play on adding support for webflux?

@gregturn
Copy link
Contributor

gregturn commented Jan 8, 2019

During S1P back in September, plans were formed to add WebFlux support to Spring HATEOAS. We haven't gotten underway with implementing, though. There was a stack of other stuff in the works that we are fervently hammering on.

Stay tuned!

@gregturn gregturn changed the title spring-webflux support Add Spring WebFlux support Feb 2, 2019
@gregturn gregturn added this to the 1.0 M1 milestone Feb 2, 2019
@gregturn gregturn self-assigned this Feb 2, 2019
gregturn added a commit that referenced this issue Feb 2, 2019
* Render hypermedia from WebFlux controllers.
* Support consuming hypermedia through WebClient.
* Support link creation reactively with a custom filter and explicitly with a user-provided ServerWebExchange.
* Add a ReactiveResourceAssembler and SimpleReactiveResourceAssembler.
* Upgrade to Spring Framework 5.2 to align with Spring Data Moore, removing specialized Forwarded header handling.
@gregturn
Copy link
Contributor

gregturn commented Feb 5, 2019

WebFlux support is now under review.

schauder added a commit that referenced this issue Feb 11, 2019
Improving some JavaDoc.
Adding issue references to tests.
Updating copyright notice.
gregturn added a commit that referenced this issue Feb 13, 2019
* Render hypermedia from WebFlux controllers.
* Support consuming hypermedia through WebClient.
* Support link creation reactively with a custom filter and explicitly with a user-provided ServerWebExchange.
* Add a ReactiveResourceAssembler and SimpleReactiveResourceAssembler.
* Upgrade to Spring Framework 5.2 to align with Spring Data Moore, removing specialized Forwarded header handling.
gregturn pushed a commit that referenced this issue Feb 13, 2019
* Improving some JavaDoc.
* Adding issue references to tests.
* Updating copyright notice.
gregturn added a commit that referenced this issue Feb 13, 2019
* Fix up issues reported by Jens.
* Add extra tests showing encoding as well as decoding.
* Properly handle Reactor types on WebFlux inputs.
* Update CI to account for the upgrade to Spring Framework 5.2.
gregturn added a commit that referenced this issue Feb 13, 2019
* Fix up issues reported by Jens.
* Add extra tests showing encoding as well as decoding.
* Properly handle Reactor types on WebFlux inputs.
* Update CI to account for the upgrade to Spring Framework 5.2.
@gregturn gregturn reopened this Feb 13, 2019
odrotbohm pushed a commit that referenced this issue Feb 15, 2019
* Render hypermedia from WebFlux controllers.
* Support consuming hypermedia through WebClient.
* Support link creation reactively with a custom filter and explicitly with a user-provided ServerWebExchange.
* Add a ReactiveResourceAssembler and SimpleReactiveResourceAssembler.
* Upgrade to Spring Framework 5.2 to align with Spring Data Moore, removing specialized Forwarded header handling.
odrotbohm added a commit that referenced this issue Feb 15, 2019
Adapt to API changes in master branch. Fixed formatting.
odrotbohm added a commit that referenced this issue Feb 15, 2019
WebHandler is now independent of a particular web stack as the final LinkBuilder creation is externalized through a SAM type that client code now uses to pass a constructor. Refactored the ReactiveLinkBuilder to avoid a dependency on ControllerLinkBuilder (read: the WebMVC stack). With that change, WebHandler is now moved back to the core package.

Refactored LinkBuilderSupport to keep a UriComponentsBuilder instance around instead of UriComponents. It creates a defensive copy of the builder instance on state modifying invocations and returns a new LinkBuilderSupport instance.

Moved SpringMvcAffordanceBuilder to the core package and removed Mvc segment from its name to make obvious it's not tied to SpringMVC. Introduced TemplateVariableAwareLinkBuilderSupport as common base class between ControllerLinkBuilder and ReactiveLinkBuilder. It extracts the TemplateVariable behavior from ControllerLinkBuilder.

Extracted import of web stack specific configuration into dedicated ImportSelector and make use of String based class names to avoid cyclic dependencies between the config packages.

Removed BasicLinkBuilder.
odrotbohm added a commit that referenced this issue Feb 20, 2019
Renamed LinkBuilder implementations for the different web stacks Web(MVC|Flux)LinkBuilder for symmetry. Introduced dedicated builder types to be used from WebFluxLinkBuilder to more conveniently integrate with reactive flows (see the changes in WebFluxEmployeeController).

Deprecated ControllerLinkBuilder(Factory) in favor of WebMvcLinkBuilder(Factory).

Generally untangled the use of WebMvcLinkBuilder from the reactive examples.
odrotbohm added a commit that referenced this issue Feb 20, 2019
odrotbohm added a commit that referenced this issue Feb 20, 2019
Renamed LinkBuilder implementations for the different web stacks Web(MVC|Flux)LinkBuilder for symmetry. Introduced dedicated builder types to be used from WebFluxLinkBuilder to more conveniently integrate with reactive flows (see the changes in WebFluxEmployeeController).

Deprecated ControllerLinkBuilder(Factory) in favor of WebMvcLinkBuilder(Factory).

Generally untangled the use of WebMvcLinkBuilder from the reactive examples.
odrotbohm added a commit that referenced this issue Feb 20, 2019
odrotbohm pushed a commit that referenced this issue Feb 20, 2019
* Render hypermedia from WebFlux controllers.
* Support consuming hypermedia through WebClient.
* Support link creation reactively with a custom filter and explicitly with a user-provided ServerWebExchange.
* Add a ReactiveResourceAssembler and SimpleReactiveResourceAssembler.
* Upgrade to Spring Framework 5.2 to align with Spring Data Moore, removing specialized Forwarded header handling.
odrotbohm added a commit that referenced this issue Feb 20, 2019
Adapt to API changes in master branch. Fixed formatting.
odrotbohm added a commit that referenced this issue Feb 20, 2019
WebHandler is now independent of a particular web stack as the final LinkBuilder creation is externalized through a SAM type that client code now uses to pass a constructor. Refactored the ReactiveLinkBuilder to avoid a dependency on ControllerLinkBuilder (read: the WebMVC stack). With that change, WebHandler is now moved back to the core package.

Refactored LinkBuilderSupport to keep a UriComponentsBuilder instance around instead of UriComponents. It creates a defensive copy of the builder instance on state modifying invocations and returns a new LinkBuilderSupport instance.

Moved SpringMvcAffordanceBuilder to the core package and removed Mvc segment from its name to make obvious it's not tied to SpringMVC. Introduced TemplateVariableAwareLinkBuilderSupport as common base class between ControllerLinkBuilder and ReactiveLinkBuilder. It extracts the TemplateVariable behavior from ControllerLinkBuilder.

Extracted import of web stack specific configuration into dedicated ImportSelector and make use of String based class names to avoid cyclic dependencies between the config packages.

Removed BasicLinkBuilder.
odrotbohm added a commit that referenced this issue Feb 20, 2019
Renamed LinkBuilder implementations for the different web stacks Web(MVC|Flux)LinkBuilder for symmetry. Introduced dedicated builder types to be used from WebFluxLinkBuilder to more conveniently integrate with reactive flows (see the changes in WebFluxEmployeeController).

Deprecated ControllerLinkBuilder(Factory) in favor of WebMvcLinkBuilder(Factory).

Generally untangled the use of WebMvcLinkBuilder from the reactive examples.
odrotbohm added a commit that referenced this issue Feb 20, 2019
odrotbohm pushed a commit that referenced this issue Feb 21, 2019
* Render hypermedia from WebFlux controllers.
* Support consuming hypermedia through WebClient.
* Support link creation reactively with a custom filter and explicitly with a user-provided ServerWebExchange.
* Add a ReactiveResourceAssembler and SimpleReactiveResourceAssembler.
* Upgrade to Spring Framework 5.2 to align with Spring Data Moore, removing specialized Forwarded header handling.
odrotbohm added a commit that referenced this issue Feb 21, 2019
Adapt to API changes in master branch. Fixed formatting.
odrotbohm added a commit that referenced this issue Feb 21, 2019
WebHandler is now independent of a particular web stack as the final LinkBuilder creation is externalized through a SAM type that client code now uses to pass a constructor. Refactored the ReactiveLinkBuilder to avoid a dependency on ControllerLinkBuilder (read: the WebMVC stack). With that change, WebHandler is now moved back to the core package.

Refactored LinkBuilderSupport to keep a UriComponentsBuilder instance around instead of UriComponents. It creates a defensive copy of the builder instance on state modifying invocations and returns a new LinkBuilderSupport instance.

Moved SpringMvcAffordanceBuilder to the core package and removed Mvc segment from its name to make obvious it's not tied to SpringMVC. Introduced TemplateVariableAwareLinkBuilderSupport as common base class between ControllerLinkBuilder and ReactiveLinkBuilder. It extracts the TemplateVariable behavior from ControllerLinkBuilder.

Extracted import of web stack specific configuration into dedicated ImportSelector and make use of String based class names to avoid cyclic dependencies between the config packages.

Removed BasicLinkBuilder.
odrotbohm added a commit that referenced this issue Feb 21, 2019
Renamed LinkBuilder implementations for the different web stacks Web(MVC|Flux)LinkBuilder for symmetry. Introduced dedicated builder types to be used from WebFluxLinkBuilder to more conveniently integrate with reactive flows (see the changes in WebFluxEmployeeController).

Deprecated ControllerLinkBuilder(Factory) in favor of WebMvcLinkBuilder(Factory).

Generally untangled the use of WebMvcLinkBuilder from the reactive examples.
odrotbohm added a commit that referenced this issue Feb 21, 2019
@odrotbohm
Copy link
Member

This is now in place with WebFluxLinkBuilder API providing a reactive builder for calls to linkTo(…). Feel free to give the latest snapshots a try. Feedback highly appreciated!

@daggerok
Copy link
Author

Hey, @odrotbohm!
Awesome! Thanks! I will try, for sure

@RouxAntoine
Copy link

Really big thanks 😃

@daggerok
Copy link
Author

daggerok commented Feb 28, 2019

Hello,

@odrotbohm, @gregturn or maybe someone else, guys maybe you have some examples where I can look how I can use WebFluxLinkBuilder? Is it required using Spring MVC styled Resources only? If not, can you please quickly show how I can use it together with functional routes?

Sorry if I'm asking dumb questions, but I wasn't able to find anything specific yet in here: https://docs.spring.io/spring-hateoas/docs/1.0.0.BUILD-SNAPSHOT/reference/html/ and in tests

Thanks in advice


Regards,
Max

@odrotbohm
Copy link
Member

It's all in quite a flux (pun intended) right now. The most practical place to look at right now is the sample controller we use in the test cases. Updating the docs is high priority, but I'm not sure we're gonna get it done in time before 1.0 M1.

@daggerok
Copy link
Author

Thanks a lot!

odrotbohm added a commit that referenced this issue Mar 4, 2019
Tweaked WebFluxLinkBuilder to make sure the controller invocations are resolved eagerly as otherwise, the controller proxy created would override the invocations due to the lazy evaluation of the links and for multiple method references, only the last one would have been used.
@jakubriegel
Copy link

@odrotbohm any news at docs for hateoas with WebFlux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants