HTTP状态code为限量珍藏? [英] HTTP status code for limited collection?

查看:142
本文介绍了HTTP状态code为限量珍藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RESTful服务,其中的收藏品之一有限(UX原因)。在这种情况下,它有25个项目的帽。如果超出资源必须以前更被删除可以增加。作为一个例子,如果一个客户端提交

I have a restful service where one of the collections is limited (for UX reasons). In this case it has a cap of 25 items. If that is exceeded resources must be deleted before more can be added. As an example if a client submits:

POST http://somesite.com/api/v2/stuff
{"cool":"stuff"}

和有<在东西25件事情:

and there are < 25 things in stuff:

200 OK

如果在东西> 25件事情:

if > 25 things in stuff:

???

DELETE http://somesite.com/api/v2/stuff/:id

POST http://somesite.com/api/v2/stuff
{"cool":"stuff"}

200 OK

什么是最好的code这个?直400? 409冲突吗? 429?似乎都不完全正确。

What is the best code for this? Straight 400? 409 CONFLICT? 429? None seem quite right..

推荐答案

使用409自的 httpbis部分7.5.8

的请求无法完成,由于当前冲突
  资源的状态。这code只允许在情况下
  预期用户可能能够解决冲突和
  重新提交请求。有效载荷应该包含足够的信息
  为用户识别冲突的来源。

"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 payload SHOULD include enough information for the user to recognize the source of the conflict."

在你的情况下,资源是一个接 http://somesite.com/api/v2/stuff 标识和 POST 的请求无法完成,由于其当前状态的冲突(这是它已经刷爆了)。在您的回复,给用户提供足够的信息(preferably链接)删除现有的成员之一,上涨的极限,或者采取一些其他动作。然后,他们可以重新提交原始请求。

In your case, the resource is the one identified by http://somesite.com/api/v2/stuff, and the POST request cannot be completed due to a conflict with its current state (which is that it is already maxed out). In your response, give the user enough info (preferably links) to delete one of the existing members, up the limit, or take some other action. Then they can resubmit the original request.

这篇关于HTTP状态code为限量珍藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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