验证失败或重复无效的REST HTTP状态代码

本文翻译自:REST HTTP status codes for failed validation or invalid duplicate

I'm building an application with a REST-based API and have come to the point where i'm specifying status codes for each requests. 我正在使用基于REST的API构建应用程序,并且到了我为每个请求指定状态代码的地步。

What status code should i send for requests failing validation or where a request is trying to add a duplicate in my database? 对于验证失败的请求,或者请求试图在数据库中添加重复项的情况,我应该发送什么状态代码?

I've looked through http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html but none of them seems right. 我已经浏览了http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html,但是似乎都不对。

Is there a common practice when sending status codes? 发送状态代码时是否有惯例?


#1楼

参考:https://stackoom.com/question/DnvS/验证失败或重复无效的REST-HTTP状态代码


#2楼

200,300, 400, 500 are all very generic. 200,300、400、500都是非常通用的。 If you want generic, 400 is OK. 如果要通用,则400即可。

422 is used by an increasing number of APIs, and is even used by Rails out of the box. 422被越来越多的API使用,甚至被Rails开箱即用。

No matter which status code you pick for your API, someon

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值