web-services - Web 服务中的 REST 无状态和用户 session

标签 web-services api http rest

我想开发一个 REST API。 REST 指南指定状态不得存储在服务器端。 但是我要实现的 REST 方法暗示了用户连接管理。为了尊重无状态,我是否需要在每个 REST 方法请求中提供用户凭据?我发现这样效率很低……难道没有其他更有效的方法吗??

最佳答案

无状态是 REST 架构的主要限制之一,可以在原文中阅读 publication :

5.1.3 Stateless

We next add a constraint to the client-server interaction: communication must be stateless in nature, as in the client-stateless-server (CSS) style of Section 3.4.3 (Figure 5-3), such that each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client.

因此,对于您提到的凭据,您应该在每次调用中分别提供它们(即基本身份验证 + SSL)。当然,这是在“真实世界”出现的情况下,应用程序开始有所不同。您也可以使用 OAuth、固定 token 等,但请记住,您正在削弱 API 的“RESTfulness”。

关于web-services - Web 服务中的 REST 无状态和用户 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4634473/

相关文章:

http - 更改处理程序时 http 测试服务器中的竞争条件

web-services - 测试公共(public) Web 服务的客户端

php - 如何在 php 中读取传入的 SOAP 请求

api - Azure dnsZone 授权失败

Java EE 1.5 API 文档下载

c# - 网络请求错误?

c# - 带有自定义 header 的 Windows Phone 8 Http 请求

java - 尝试访问 Websphere 7.0 版本中的特定 URI 时遇到问题

java - Apache CXF 客户端代理设置

python - Python : Get songs Lyrics from genius - Error