简体   繁体   English

使用 spring HATEOAS 和 spring webflux 功能 Web 框架 (reactor.netty)

[英]Using spring HATEOAS with spring webflux Functional Web Framework (reactor-netty)

Can we use spring HATEOAS on top of RouterFunction ?我们可以在HATEOAS之上使用 spring RouterFunction吗? I imagine that we can specify the resource but what will be the equivalent of the linkto(Controller.class) ?我想我们可以指定资源,但是linkto(Controller.class)的等价物是什么? or is there any equivalent to specify the link and use composition of RouterFunction或者是否有任何等价物来指定RouterFunction的链接和使用组合

By definition, you're creating a custom route and Spring HATEOAS<\/code> is an opinionated set of frameworks meant so you don't have to lift a finger.根据定义,您正在创建一个自定义路由,而 Spring HATEOAS<\/code>是一组固执己见的框架,因此您不必费力。 What you are trying to do, and what Spring HATEOAS<\/code> is doing are contradictory.您正在尝试做的事情与 Spring HATEOAS<\/code>正在做的事情是矛盾的。 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 . 2023年1月答复:还没有

Spring HATEOAS was originally built with Spring MVC in mind, so even WebFluxLinkBuilder relies on Controller annotations to build the resource links. Spring HATEOAS 最初是用 Spring MVC 构建的,因此即使是 WebFluxLinkBuilder 也依赖 Controller 注释来构建资源链接。

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. RouterFunction 接口没有公开底层 RequestPredicate 的方法,因此无法确定哪个路径与给定的 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.在未来 API 中可能会引入一些方法来提供对开箱即用的信息的所需访问,而不必做一些讨厌的事情,比如用反射破坏封装。 In the meantime, you'd probably need to consider centralizing all relevant RouterFunction creation (eg via a helper/util/custom builder class), so you can intercept all paths and the associated HandlerFunctions with some degree of confidence.同时,您可能需要考虑集中所有相关的 RouterFunction 创建(例如,通过 helper/util/custom builder 类),这样您就可以在一定程度上自信地拦截所有路径和相关的 HandlerFunction。

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.是的,当您使用 RouterFunctions 时,不幸的是 Spring HATEOAS 无法帮助创建链接,并且基于当前的 WebFlux 功能 API 以通用方式可靠地实现此功能具有挑战性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM