gpt4 book ai didi

rest - HATEOAS 是否暗示查询字符串不是 RESTful?

转载 作者:行者123 更新时间:2023-12-03 23:30:58 27 4
gpt4 key购买 nike

HATEOAS(作为应用程序状态引擎的超媒体)建议是否暗示查询字符串不是 RESTful?

编辑:下面建议查询字符串可能与状态没有太大关系,因此这个问题令人费解。我建议 URI 具有查询字符串没有意义,除非客户端填写参数。如果客户端正在填充参数,那么它就是在篡改服务器提供的 URI,我想知道这是否违反了 RESTful 原则。

编辑 2:我意识到如果客户端将查询字符串视为不透明(并且查询字符串可能是遗留的,因此很方便),它似乎是无害的。但是,在下面的一个答案中引用了 Roy Fielding 的话说,URI 应该是透明的。如果它是透明的,那么我相信掺假是被鼓励的,这似乎淡化了 HATEOAS 原则。这种稀释是否仍然与 HATEOAS 一致?这就提出了一个问题,即 REST 是否要求 URI 构建似乎是紧密耦合的。

更新 在本 REST 教程中 http://rest.elkstein.org/建议 URI 构建是糟糕的设计,不是 RESTful。它还重复了@zoul 在接受的答案中所说的内容。

For example, a "product list" request could return an ID per product, and the specification says that you should use http://www.acme.com/product/PRODUCT_ID to get additional details. That's bad design. Rather, the response should include the actual URL with each item: http://www.acme.com/product/001263, etc. Yes, this means that the output is larger. But it also means that you can easily direct clients to new URLs as needed



如果有人正在查看此列表并且不想要他/她可以看到的内容,则可能会有“前 10 项”和“后 10 项”按钮,但是,如果没有人,而是客户端程序,REST 的这方面似乎有点奇怪,因为客户端程序可能没有用的所有“ http://www”。

最佳答案

I would suggest that it doesn't make sense for the URI to have a query string unless the client were filling in arguments.



这对我来说似乎不是真的。如果你向服务器索要一些照片,服务器返回这样的东西是完全有效的:
<photos>
<photo url="http://somewhere/photo?id=1"/>
<photo url="http://somewhere/photo?id=2"/>
</photos>

您可以使用 /photo/id/xx路径,但这不是重点。即使客户端不更改这些 URL,它们也可用。至于你的第二点:

If the client is filling arguments then it is adulterating the server-supplied URI and I wonder if this violates the RESTful principle.



我想这是你问题的核心。而且我认为您不必将 URL 视为不透明的标识符,请参阅 this quote罗伊·菲尔丁本人:

REST does not require that a URI be opaque. The only place where the word opaque occurs in my dissertation is where I complain about the opaqueness of cookies. In fact, RESTful applications are, at all times, encouraged to use human-meaningful, hierarchical identifiers in order to maximize the serendipitous use of the information beyond what is anticipated by the original application.

关于rest - HATEOAS 是否暗示查询字符串不是 RESTful?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4601777/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com