rest - "You must POST here before doing anything else"的正确 REST 响应

标签 rest

我们有一个登录 REST 服务:

POST /sessions

当用户密码过期时,接下来必须发生的事情是客户端应用程序将显示一个更改对话框窗口,然后通过以下方式更改用户密码:

PUT /users/_ID_/password

向客户传达这一意图的最佳方式是什么?起初我想让 POST/sessions 返回 See Other (303)。但这会导致 /users/_ID_/password 上发生 GET。我可以返回一个 Multiple Choices (300) 响应,客户端不会自动获取该响应,或者我可以返回一个 OK (200) 并在 JSON session 中标记返回对象。

最佳答案

看看HTTP status code definitions ,我认为以下是最合适的:

409 Conflict

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem

与 session 资源的当前状态存在冲突,因为用户需要更改密码才能创建 session 。您可以在此响应中返回更改密码屏幕的 URL,以便客户端知道去哪里解决冲突。

关于rest - "You must POST here before doing anything else"的正确 REST 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10313878/

相关文章:

python - 遍历python中的dict和list

rest - OPTIONS 请求使用 CORS 进行 Restful 跨域

java - 使用 SMSLib 和 Web 服务发送 SMS

spring - 内容类型 'multipart/form-data;boundary=----WebKitFormBoundary...' 不支持 Spring

java - 使用 java 客户端传递 json 对象调用 Rest API

node.js - $http DELETE 变成 OPTIONS AngularJS

api - 使用 RESTful API 进行客户端和服务器端验证

java - 在 Spring Boot 中处理剩余 Controller 中的异常

java - YouTrack REST API : How to attach image to issue?

rest - 使用拦截器和注入(inject)在 JAX-RS 中进行身份验证/授权