我正在设计一个用于注册类(class)的 REST API。在我的端点中,我可以POST
注册:
POST to http://my-api/class/learn-rest/enrollment
这会创建一个新的注册。但是,在这种情况下,只能有固定数量的注册,假设 5 个。
当用户尝试添加第 6 个注册时,我应该返回哪个 HTTP 响应代码?
最佳答案
好问题。不知道为什么它被否决了。
我建议使用 400。如果您找不到针对 4xx 错误的特定且适当的状态代码,则应该使用它。
- 409:这是不合适的,因为它通常是可重试的。但在您的情况下重试肯定会解决问题。
- 429:它也是可重试的。
做了更多研究(一些著名的 api 提供商使用的做法)
LimitExceededException: Returned if the request results in one of the following limits being exceeded, a vault limit, a tags limit, or the provisioned capacity limit. 400 Bad Request
https://docs.aws.amazon.com/amazonglacier/latest/dev/api-error-responses.html
Unless a more specific error status is appropriate for the given request, services SHOULD return "400 Bad Request" and an error payload conforming to the error response guidance provided in the Microsoft REST API Guidelines.
https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#1521-error-response
关于rest - 资源最大响应代码。 REST API 的限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49607453/