休息时的无国籍状态

Statelessness in Rest

我正在阅读一本关于 Rest 体系结构的书,偶然发现了这一部分

In particular, the application must be separated into a client-server model and the server must remain completely stateless. No client context may be stored on the server and resources should also be uniquely and uniformly identified.

1。服务器保持完全无状态是什么意思?

2。服务器上可能没有存储客户端上下文?什么客户端上下文?

感谢任何有助于分解此问题的帮助。

what does it mean for the server to remain completely stateless?

这意味着发送到服务器的每条消息都被认为是完整的;服务器不应 "remembering" 来自客户端的先前消息。

考虑买一本书。

Client: What's the price of [Rest in Practice: Hypermedia and Systems Archicture]
Server: The price of [Rest in Practice: Hypermedia and Systems Archicture] is 36.16 USD.
Client: Buy it.

服务器要知道"it"是什么意思,必须记住之前关于书价的对话,才能知道客户端说的是哪本书。

无状态意味着客户端从不使用代词

无状态版本看起来像

Client: Buy [Rest in Practice: Hypermedia and Systems Archicture].

服务器需要知道的有关客户端当前状态的所有信息都包含在消息中。也许这个客户先问了价格,也许没有。没关系,因为所有信息都在这里,在此消息中。

考虑这个序列:

Client: What's the price of [Rest in Practice: Hypermedia and Systems Archicture]
Server: The price of [Rest in Practice: Hypermedia and Systems Archicture] is 36.16 USD.
Client: What's the price of [Royal Oak Tourbillon]
Server: The price of [Royal Oak Tourbillon] is 122000.00 USD.
Client: Buy it.

你刚买了 book, or a wrist watch 吗?服务器不知道您是否点击后退按钮。