“状态转移”是什么意思?表述性状态转移(REST)中指的是?

发布于 2024-10-10 10:11:34 字数 255 浏览 0 评论 0原文

代表性状态转移中的状态转移指的是什么?

找到了一些关于此的解释(例如此处),但我仍然不明白。例如文章中说

该表示将客户端应用程序置于某种状态。

为什么?状态(据我所知,类似于会话)与资源的表示有什么关系?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

世界和平 2024-10-17 10:11:34

为什么?状态(据我所知,类似于会话)与资源的表示有什么关系?

对象具有属性(或状态)和行为(或方法)。

如果我想将对象从桌面移动到服务器,我必须执行以下操作:

  1. 创建对象状态的表示。

  2. 将该表示从桌面传输到服务器。

这些方法我就不转述了。我在两台机器上安装相同的类定义。

因此,REST 是关于创建对象当前状态的表示,以便可以将其传输到可以重建对象的另一台服务器。

我们只发送对象的状态——属性。我们必须创建该状态的外部序列化表示。

Why? What does state (as I understand it, something like a session) have to do with a representation of a resource?

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:

  1. Create a representation of the state of the object.

  2. 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.

寂寞笑我太脆弱 2024-10-17 10:11:34

将客户端应用程序视为一种巨型状态机。客户端的初始状态等于从服务器返回的第一个表示。返回的表示中的链接提供了可能的“状态转换”。

需要注意的一件事是,有两种主要类型的链接:被动链接和主动链接。像 这样的被动链接实际上不会导致状态转换,它们只是增强当前状态。然而,像

这样的链接是活动链接,会导致状态转换。在点击其中一个链接后,新的客户端状态等于返回的表示,也称为状态转移

如果您习惯于构建传统的桌面客户端应用程序,您会发现这是一个完全不同的架构。不是一个你可能一夜之间就能掌握的东西。最初,这种方法可能看起来非常有限,但是当您考虑到客户端应用程序可以是许多同时执行的状态机的主机时,您将开始意识到您可以使用远程对象体系结构执行几乎任何操作,并且仍然保持松散的状态。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文