rest - 注册期间现有电子邮件的 422 或 409 状态代码

标签 rest api http

我在构建 RESTful API 时遇到过一种情况。在用户注册期间,如果电子邮件已经存在,那么 422409 之间哪个 http 响应代码有意义?

我浏览过类似的 one并且接受的答案来自 2012 年。答案仍然有效吗?例子会有很大帮助。

最佳答案

你可能找不到这个问题的非常明确的答案,一旦两者409422适合这种情况(不过我会选择 409)。

对于其中任何一个,您必须确保将描述问题的有效负载发送回客户端。

6.5.8. 409 Conflict

The 409 (Conflict) status code indicates that the request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request. The server SHOULD generate a payload that includes enough information for a user to recognize the source of the conflict. [...]

11.2. 422 Unprocessable Entity

The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415 (Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.

关于rest - 注册期间现有电子邮件的 422 或 409 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50946698/

相关文章:

http - REST 架构风格是否需要在物理上分离客户端和服务器?

javascript - 如何为从移动和 JavaScript Web 应用程序访问的 rest API 实现基于 token 的 OAuth 2.0 身份验证

http - 使用参数发出简单的 post 请求并接收响应

Angular HttpClient post 请求类型

php - Django 、Python : Is there a simple way to convert PHP-style bracketed POST keys to multidimensional dict?

java - Spring Data Rest PATCH 禁止更新特定字段

spring - 以编程方式控制 @RestController 可用性

c++ - 一个数据包读取器Qt/C++ API设计

c# - 如何通过 SharpTelegram 在 C# 中使用 Telegram Api

java - 折线颜色不变