Using spring HATEOAS with spring webflux Functional Web Framework (reactor-netty)
Asked Answered
M

2

63

Can we use spring HATEOAS on top of RouterFunction ? I imagine that we can specify the resource but what will be the equivalent of the linkto(Controller.class) ? or is there any equivalent to specify the link and use composition of RouterFunction

Moravian answered 6/9, 2017 at 9:23 Comment(3)
#45651253Myo
Does this answer your question? HATEOAS on Spring Flux/Mono responseStannite
Here you find the issue for this topic: github.com/spring-projects/spring-hateoas/issues/996Zsigmondy
S
1

By definition, you're creating a custom route and Spring HATEOAS is an opinionated set of frameworks meant so you don't have to lift a finger. What you are trying to do, and what Spring HATEOAS is doing are contradictory. So, you will have to manually create the payload if you want embedded hyperlinks.

Although, this shouldn't be too difficult if you set your owner content handler for your specific return type on that route.

Shackleton answered 31/1, 2022 at 19:26 Comment(0)
C
0

Answer in January 2023: not yet.

Spring HATEOAS was originally built with Spring MVC in mind, so even WebFluxLinkBuilder relies on Controller annotations to build the resource links.

The RouterFunction interface has no methods that expose the underlying RequestPredicate, so there is no way to determine which path is associated with a given RouterFunction. Some method may be introduced in a future API to provide the needed access to that information out-of-the-box, without having to do something nasty like breaking encapsulation with Reflection. In the meantime, you'd probably need to consider centralizing all relevant RouterFunction creation (e.g. via a helper/util/custom builder class), so you can intercept all paths and the associated HandlerFunctions with some degree of confidence.

Yeah, when you use RouterFunctions, unfortunately Spring HATEOAS does not help creating the links, and it is challenging to reliably implement this functionality in a generic way based on the current WebFlux functional API.

Cranmer answered 30/1, 2023 at 4:9 Comment(2)
By the way, I eventually managed to do it by implementing my own LinkBuilder that uses the ApplicationContext to retrieve the RouterFunction, as it became clear Spring HATEOAS really can't do it out-of-the-box.Cranmer
Flavio: Care to share how you did it?Bloodfin

© 2022 - 2024 — McMap. All rights reserved.