注册期间现有电子邮件的 422 或 409 状态代码 [英] 422 or 409 status code for existing email during signup

查看:38
本文介绍了注册期间现有电子邮件的 422 或 409 状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我浏览过类似的 one 和接受的答案是从 2012 年开始的.答案仍然有效吗?示例会很有帮助.

解决方案

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

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

<块引用>

6.5.8.409冲突

409(冲突)状态代码表示请求无法由于与目标的当前状态冲突而完成资源.此代码用于用户可能能够解决冲突并重新提交请求.服务器应该为用户生成一个包含足够信息的负载认识到冲突的根源.[...]

<块引用>

11.2.422无法处理的实体

422(不可处理实体)状态码表示服务器了解请求实体的内容类型(因此415(不支持的媒体类型)状态代码不合适),以及请求实体的语法是正确的(因此是 400(错误请求)状态代码不合适)但无法处理包含的指示.例如,如果 XML请求正文包含格式正确(即语法正确),但语义错误的 XML 指令.

I am building RESTful API and I have come across a situation. During user sign up, if the email already exists then between 422 and 409 which http response code makes sense?

I have browsed through similar one and the accepted answer is from the year 2012. Does the answer still hold good? Examples would be of great help.

解决方案

You may not find a very definitive answer to this question, once both 409 and 422 would be suitable for this situation (I would go for 409 though).

For any of them, you must ensure that a payload describing the problem is sent back to the client.

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.

这篇关于注册期间现有电子邮件的 422 或 409 状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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