有限收集的 HTTP 状态代码? [英] HTTP status code for limited collection?

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

问题描述

我有一个安静的服务,其中一个集合是有限的(出于 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

最好的代码是什么?直400?409 冲突?429?没有一个似乎完全正确..

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

推荐答案

使用 409.来自 httpbis 第 7.5.8 节:

Use 409. From httpbis section 7.5.8:

"由于与当前的冲突,请求无法完成资源的状态.仅在以下情况下才允许使用此代码预计用户可能能够解决冲突并重新提交请求.有效载荷应该包含足够的信息以便用户识别冲突的来源."

"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 请求无法完成与其当前状态发生冲突(即它已经被最大化).在您的回复中,为用户提供足够的信息(最好是链接)以删除现有成员之一、提高限制或采取其他一些措施.然后他们可以重新提交原始请求.

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 状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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