“状态转移”是什么意思?表述性状态转移(REST)中指的是?
What does the State Transfer in Representational State Transfer refer to?
Found some explanations about this (e.g. here) but I still don't understand. For example in the article it is said
The representation places the client application in a state.
Why? What does state (as I understand it, something like a session) have to do with a representation of a resource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对象具有属性(或状态)和行为(或方法)。
如果我想将对象从桌面移动到服务器,我必须执行以下操作:
创建对象状态的表示。
将该表示从桌面传输到服务器。
这些方法我就不转述了。我在两台机器上安装相同的类定义。
因此,REST 是关于创建对象当前状态的表示,以便可以将其传输到可以重建对象的另一台服务器。
我们只发送对象的状态——属性。我们必须创建该状态的外部序列化表示。
An object has attributes (or state) and behaviors (or methods).
If I want to move an object from my desktop to a server I have to do the following:
Create a representation of the state of the object.
Transfer that representation from the desktop to the server.
The methods I don't transfer. I install the same class definition on both machines.
So, REST is about creating a representation of the object's current state so it can be transferred to another server from which the object can be reconstructed.
We only send the state -- the attributes -- of the object. And we have to create an external, serialized representation of that state.
将客户端应用程序视为一种巨型状态机。客户端的初始状态等于从服务器返回的第一个表示。返回的表示中的链接提供了可能的“状态转换”。
需要注意的一件事是,有两种主要类型的链接:被动链接和主动链接。像
和
这样的被动链接实际上不会导致状态转换,它们只是增强当前状态。然而,像
如果您习惯于构建传统的桌面客户端应用程序,您会发现这是一个完全不同的架构。不是一个你可能一夜之间就能掌握的东西。最初,这种方法可能看起来非常有限,但是当您考虑到客户端应用程序可以是许多同时执行的状态机的主机时,您将开始意识到您可以使用远程对象体系结构执行几乎任何操作,并且仍然保持松散的状态。 Web 浏览器的耦合。
Consider a client application to be a kind of giant state machine. The client's initial state is equal to the first representation returned from the server. Links in the returned representation provide possible "state transitions".
One thing to note is that there are a two major types of links, passive and active. Passive links like
<img>
and<link rel="stylesheet">
do not actually cause a state transition, they simply augment the current state. Links like<form>
and<a>
however are active links and the cause a state transition. After following one of these links the new client state is equal to the returned representation, aka state transfer.If you are used to building traditional desktop client applications you will find this is a radically different architecture. Not one that you are likely to grok overnight. Initially this approach may seem very limiting but when you consider that a client application can be the host to many simultaneously executing state machines you will start to realize that you can do just about anything that you could using a remote object architecture and still maintain the loose coupling of web browser.