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
Using spring HATEOAS with spring webflux Functional Web Framework (reactor-netty)
2.8k Views Asked by hba At
2
There are 2 best solutions below
0
On
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.
Answer in January 2023: not yet.
Spring HATEOASwas originally built with Spring MVC in mind, so evenWebFluxLinkBuilderrelies on Controller annotations to build the resource links.The
RouterFunctioninterface has no methods that expose the underlyingRequestPredicate, so there is no way to determine which path is associated with a givenRouterFunction. 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 withReflection. In the meantime, you'd probably need to consider centralizing all relevantRouterFunctioncreation (e.g. via a helper/util/custom builder class), so you can intercept all paths and the associatedHandlerFunctionswith some degree of confidence.Yeah, when you use
RouterFunctions, unfortunatelySpring HATEOASdoes 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.