达到许可证限制的 HTTP 状态代码是什么
What is the HTTP status code for License limit reached
我想知道当达到用户许可时API应该return的理想 HTTP 状态代码是什么?
最初我以为是 402(需要付款),但这不是我的情况。我的情况是,如果我的用户有添加 10 个插件的限制,如果她尝试添加第 11 个插件,他们应该会收到已达到限制的错误消息。
请为此提供适当的 HTTP 状态代码。
提前致谢
422 Unprocessable Entity 应该适用于这种情况。请求本身的语法结构良好。问题是在当前条件下,因为用户达到了限制。错误响应应该有助于如何解决这种现状。 https://httpstatuses.com/422
我的第二个赌注是 409 冲突,但与版本控制和冲突更改有关。 https://httpstatuses.com/409
没有 超出配额 的 HTTP 状态代码,但是如果您在响应有效负载中添加了良好的描述,则有一些 HTTP 状态代码适用于这种情况。
如果已超过请求配额,但可以在付款后执行更多请求,您可以考虑 402
状态代码(即使文档说它保留供将来使用,其原因短语非常清楚并且很好地定义了它的目的):
The 402
(Payment Required) status code is reserved for future use.
您可以使用403
表示当超过请求配额时禁止请求。总是欢迎在请求有效负载中进行良好的描述:
The 403
(Forbidden) status code indicates that the server understood
the request but refuses to authorize it. A server that wishes to
make public why the request has been forbidden can describe that
reason in the response payload (if any). [..]
如果您对每个 hour/day 的请求数量应用限制,429
状态代码可能适合您的需要(但是服务器也使用此状态代码来表明短时间内收到了很多请求,即客户端正在节流):
The 429
status code indicates that the user has sent too many
requests in a given amount of time ("rate limiting").
The response representations SHOULD include details explaining the
condition, and MAY include a Retry-After
header indicating how long
to wait before making a new request.
For example:
HTTP/1.1 429 Too Many Requests
Content-Type: text/html
Retry-After: 3600
<html>
<head>
<title>Too Many Requests</title>
</head>
<body>
<h1>Too Many Requests</h1>
<p>I only allow 50 requests per hour to this Web site per
logged in user. Try again soon.</p>
</body>
</html>
Note that this specification does not define how the origin server
identifies the user, nor how it counts requests. For example, an
origin server that is limiting request rates can do so based upon
counts of requests on a per-resource basis, across the entire server,
or even among a set of servers. Likewise, it might identify the user
by its authentication credentials, or a stateful cookie.
Responses with the 429
status code MUST NOT be stored by a cache.
HTTP status codes are extensible. If the aboved mentioned status codes do not fit your needs, you could create your own status. Since it's a client error, the new status code should be in the 4xx
范围。
我认为这是一个“业务逻辑错误”和422 不可处理的实体,可以更好。
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.
我想知道当达到用户许可时API应该return的理想 HTTP 状态代码是什么?
最初我以为是 402(需要付款),但这不是我的情况。我的情况是,如果我的用户有添加 10 个插件的限制,如果她尝试添加第 11 个插件,他们应该会收到已达到限制的错误消息。
请为此提供适当的 HTTP 状态代码。
提前致谢
422 Unprocessable Entity 应该适用于这种情况。请求本身的语法结构良好。问题是在当前条件下,因为用户达到了限制。错误响应应该有助于如何解决这种现状。 https://httpstatuses.com/422
我的第二个赌注是 409 冲突,但与版本控制和冲突更改有关。 https://httpstatuses.com/409
没有 超出配额 的 HTTP 状态代码,但是如果您在响应有效负载中添加了良好的描述,则有一些 HTTP 状态代码适用于这种情况。
如果已超过请求配额,但可以在付款后执行更多请求,您可以考虑 402
状态代码(即使文档说它保留供将来使用,其原因短语非常清楚并且很好地定义了它的目的):
The
402
(Payment Required) status code is reserved for future use.
您可以使用403
表示当超过请求配额时禁止请求。总是欢迎在请求有效负载中进行良好的描述:
The
403
(Forbidden) status code indicates that the server understood the request but refuses to authorize it. A server that wishes to make public why the request has been forbidden can describe that reason in the response payload (if any). [..]
如果您对每个 hour/day 的请求数量应用限制,429
状态代码可能适合您的需要(但是服务器也使用此状态代码来表明短时间内收到了很多请求,即客户端正在节流):
The
429
status code indicates that the user has sent too many requests in a given amount of time ("rate limiting").The response representations SHOULD include details explaining the condition, and MAY include a
Retry-After
header indicating how long to wait before making a new request.For example:
HTTP/1.1 429 Too Many Requests Content-Type: text/html Retry-After: 3600 <html> <head> <title>Too Many Requests</title> </head> <body> <h1>Too Many Requests</h1> <p>I only allow 50 requests per hour to this Web site per logged in user. Try again soon.</p> </body> </html>
Note that this specification does not define how the origin server identifies the user, nor how it counts requests. For example, an origin server that is limiting request rates can do so based upon counts of requests on a per-resource basis, across the entire server, or even among a set of servers. Likewise, it might identify the user by its authentication credentials, or a stateful cookie.
Responses with the
429
status code MUST NOT be stored by a cache.
HTTP status codes are extensible. If the aboved mentioned status codes do not fit your needs, you could create your own status. Since it's a client error, the new status code should be in the 4xx
范围。
我认为这是一个“业务逻辑错误”和422 不可处理的实体,可以更好。
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.