gpt4 book ai didi

java - 您能否提供讨论使用资源状态而不是 session 或数据库状态的信息或链接?

转载 作者:行者123 更新时间:2023-11-30 01:39:05 26 4
gpt4 key购买 nike

There is a talk here by Stefan Tilkov ,他在其中描述了 REST 架构的核心。我没有看完全部内容,但在他谈论 REST 5 个原则(幻灯片 12-19)的部分中,他提到通过资源(即 URI)维护状态。他的例子是购物车。通常,您的购物车的状态在 session 中维护,但他评论(此处解释)这是一个不正确的接口(interface)实现,因为您无法将 session “发送”给同事,但您可以发送资源状态,然后它将包含您购物车中的所有商品。我发现这个概念很有趣,我想知道是否有人有任何其他信息、资源、链接、视频等,可以实际讨论此类事物的架构实现(最好是用 Java)。谢谢!

编辑:

抱歉,我要在这里做一个简短的编辑 - 我不是在谈论想要有关 REST 实现本身的信息,而是想要了解实际广泛使用资源状态而不是 session /数据库状态的缺点/优点。

最佳答案

对 session 状态缺点最清晰的解释之一直接来自 Roy Fielding 的 dissertation他在其中介绍了 REST。 (重点是我的)

We next add a constraint to theclient-server interaction:communication must be stateless innature, as in theclient-stateless-server (CSS) style ofSection 3.4.3 (Figure 5-3), such thateach request from client to servermust contain all of the informationnecessary to understand the request,and cannot take advantage of anystored context on the server.

Sessionstate is therefore kept entirely onthe client.

This constraint induces the properties of visibility, reliability,and scalability.

Visibility isimproved because a monitoring systemdoes not have to look beyond a singlerequest datum in order to determinethe full nature of the request.

Reliability is improved because iteases the task of recovering frompartial failures [133].

Scalability isimproved because not having to storestate between requests allows theserver component to quickly freeresources, and further simplifiesimplementation because the serverdoesn't have to manage resource usageacross requests.

罗伊接着说,应用此约束是一种设计权衡,这种选择会产生负面影响。

一旦您选择不在应用程序架构中使用 session 状态,那么您就只能通过以下两种方式之一来维护购物车等内容。购物车要么完全由客户端应用程序维护,要么存储为资源状态。某些东西之所以成为资源,是因为它由 URI 标识,并且可以通过接口(interface)的标准动词进行操作。如果您确实将购物车存储为资源,那么正如 Stefan 所说,您可以将该资源的链接发送给同事。通过这种方法,可以像处理任何其他资源一样实现购物车。

关于java - 您能否提供讨论使用资源状态而不是 session 或数据库状态的信息或链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1662817/

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