REST 中的 ST(State Transfer) 是否意味着状态必须由客户端持有? [英] Does ST(State Transfer) in REST mean that state must be held by client?

查看:25
本文介绍了REST 中的 ST(State Transfer) 是否意味着状态必须由客户端持有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了什么是状态转移""在 Representational State Transfer (REST) 中指的是? 以及一些关于 REST 的帖子或视频,我知道 REST 的约束之一是无状态.

I read What does "state transfer" in Representational State Transfer (REST) refer to? and several post or videos about REST, and I know one of the constraint of REST is stateless.

  1. 根据许多帖子,如 http://www.restapitutorial.com/lessons/whatisrest.html ,为了使架构无状态,客户端必须持有足够的信息让服务器做正确的事情,这意味着服务器没有任何客户端状态.那么这是否意味着我们只能通过在客户端中放置一些用户状态(如 cookie)来构建 REST 应用程序?

  1. According to many posts like http://www.restapitutorial.com/lessons/whatisrest.html ,to make the architecture stateless, the client must hold the enough information for the server to do the right thing, which means the server does not have any client state. So does it mean we are only about to build a REST application only through putting some user state in the client like cookie?

但根据许多帖子,如 Sticky Session/Session Affinity 负载均衡策略的优缺点? ,我们可以通过将用户数据存储在数据库或内存缓存中来制作无状态应用程序,从而避免将会话存储在应用程序服务器中.如果我们尝试这种方法,我们可以制作一个 REST 架构吗?

But according to many posts like Pros and Cons of Sticky Session / Session Affinity load blancing strategy? , we can make a stateless application by storing the user data in database or memcache, which avoid storing session in the application server. If we try this approach, can we make a REST architecture?

推荐答案

诚实 REST 服务的理念是允许与任何客户端轻松通信,即使是不在 Web 浏览器中的客户端:它可以是移动的或桌面应用程序或其他任何东西.因此,对服务的每个请求都必须提供所有必要的信息来处理该请求.将状态保持在服务器上会使任务复杂化,因为客户端将无法控制它.

The idea of honest REST service is to allow easy communication with it to any client, even to the client that is not in a web browser: it could be mobile or desktop application or anything else. So, each request to the service must provide all necessary information to process that request. Keeping the state on server would complicate the task, because clients will not control it.

所以,是的,理想情况下状态必须由客户持有.但是,我们需要清楚地理解状态"是什么意思.因为有不同种类的状态:Application 状态和 Resource 状态.我喜欢以下关于区别的文章.

So, YES, ideally state must be held by clients. BUT, we need to understand clearly what we mean by "state". Because there are different kinds of state out there: Application state, and Resource state. I like the following article about the distinction.

附言顺便说一句,在 cookie 中保存状态也会使客户的生活变得复杂(如果他们不是网络浏览器).

P.S. And BTW, keeping state in cookies would complicate life to clients as well(if they are not web-browsers).

这篇关于REST 中的 ST(State Transfer) 是否意味着状态必须由客户端持有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆