'stateless'在rest和Http中的含义

The meaning of 'stateless' in rest and Http

当我阅读有关什么是 REST 的文档时,他们总是说 REST api 应该是无状态的。在这里,我觉得有点尴尬,因为普通的 HTTP 也是无状态的。

既然REST可以说是一种使用HTTP协议的特殊架构,那么说REST应该是无状态的似乎是多余的。

'stateless' 这个词在 REST 和 HTTP 中的意思是一样的吗? 如果不是请告诉我区别


我问的不是stateless in http的意思,而是stateless in rest和http的区别

HTTP 术语中的无状态意味着每个请求都不知道任何先前的请求,即 HTTP 中没有内置机制来跟踪谁在发出请求以及这些请求的影响。

就 RESTful 服务而言,这意味着每个请求不依赖状态(例如,保存的客户端信息)来完成请求——完成请求所需的所有信息都包含在请求消息(CRUD 操作、相关资源、授权令牌、应用程序平台标识等)。

这意味着您的 RESTful API 应该受到管理身份验证、会话管理和其他非 RESTful 操作的分层架构的保护。

在此上下文中,RESTful 服务和 HTTP 都应在相同的约束下运行:无状态(如上定义)。


像这样设计 REST API 似乎很直观,但您会惊讶于在许多 REST 服务的核心发现的紧密耦合:

GET /users/:id

if authenticated and authorized //not stateless
    send User resource

为了解决这个问题,大多数 HTTP 框架都提供了中间件层。


有用的 REST 设计问题:

REST代表Representational State Transfer,表示状态是具象的。 api 服务器上未保留请求跟踪机制或会话。请求的状态可能会传输到其他 api 服务器。

此外,像 GET /users/:id 这样的约定声明每个资源都有一个内置的识别机制 url 因此不需要像 [=19= 那样跟踪请求中的资源]本身包含客户端资源请求信息eg:GET/users/1,PUT/users/1.

Does the word 'stateless' means the same thing in both REST and HTTP?

是的。

它们相同的原因是 HTTP 是 REST 的结果。

Since 1994, the REST architectural style has been used to guide the design and development of the architecture for the modern Web -- Fielding, 2000.

在他的论文之前,菲尔丁是 RFC 2068 and RFC 2616.

的作者

Just for clarification, could you tell me what '"the principles that are now called REST were refined through Fielding's work on HTTP.' means?

Reflections on the REST Architectural Style includes a timeline: the first implementations of HTTP were in 1990-91, Fielding started participating in 1993. During the specification process (RFC 1945, RFC 2068, RFC 2616) 的第一节 Fielding 开发了一种“HTTP 对象模型”,后来被理解为“REST 架构风格”。

The first edition of REST was developed between October 1994 and August 1995, primarily as a means for communicating Web concepts as we wrote the HTTP/1.0 specification and the initial HTTP/1.1 proposal. -- Fielding

也就是说,REST 的思想是与 HTTP 的标准化并行发展的,作为一个预言机:我们如何评估一个提案是否会破坏或破坏 HTTP 的重要属性?网站?

Section 6.3.4 of the thesis 描述了一些标准化的不匹配的后果。