rest - 资源最大响应代码。 REST API 的限制?

标签 rest http post httpresponse http-response-codes

我正在设计一个用于注册类(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/

相关文章:

java - Spring REST 多部分错误处理

java - 如何为 Android AsyncTask 类建模?

java - 如何使用 REST 将二进制文件从 JQuery 客户端发布到 Java 服务器

jquery - Cordova 应用程序的 AJAX 请求返回 'status=0'

php - 在 php 和 dart 之间发送数据

javascript - 基于Json的架构怎么称呼?

rest - 如何使用webpack设置rest api的基本路径

java - 从 Jersey 调用@POST

php - 从Android应用程序上传图像到服务器不工作

javascript - AngularJS:使用 $http.get 检索数据并使其可用