达到许可证限制的HTTP状态代码是什么 [英] What is the HTTP status code for License limit reached

查看:99
本文介绍了达到许可证限制的HTTP状态代码是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在达到用户许可后API应该返回的理想HTTP状态代码是什么?

I want to know what is the ideal HTTP status code an API should return when a user's license has reached?

最初,我在考虑它的402(需要付款),但这不是我的情况.我的情况是,如果我的用户限制添加10个插件,而她尝试添加第11个插件,他们应该得到一个错误,指出已达到限制.

Initially I was thinking its 402 (Payment Required) but this is not my scenario. My case is if my user has a limit to add 10 plugins, if she tries to add the 11th plugin they should get an error that their limit has reached.

请为我提供适当的HTTP状态代码.

Please help me with the appropriate HTTP status code for this.

预先感谢

推荐答案

没有超出 quota的HTTP状态代码,但是有一些HTTP状态代码适合您的情况在响应有效负载中添加良好的描述.

There's no HTTP status code for quota exceeded, however there are a few HTTP status code that would be suitable for this situation provided you add a good description in the response payload.

如果超出了请求配额,但是可以在付款后执行更多请求,则可以考虑使用402状态代码(即使文档说它已保留供将来使用,其原因也很清楚,并且很好地定义了它的目的):

If the quota of requests has been exceeded, but more requests could be performed upon a payment, you could consider the 402 status code (even though the documentation says it's reserved for future use, its reason phrase is pretty clear and defines well its purpose):

6.5.2. 402需要付款

402(需要付款)状态码保留供将来使用.

The 402 (Payment Required) status code is reserved for future use.

您可以使用403来指示超出请求配额时该请求被禁止.始终欢迎在请求有效负载中提供良好的描述:

You could use 403 to indicate the request is forbidden when the quota of requests has been exceeded. A good description in the request payload is always welcome:

6.5.3. 403禁止

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). [..]

如果您对每小时/每天的请求数量施加限制,则429状态代码可能适合您的需求(但是服务器使用此状态代码来表示在其中接收到太多请求在很短的时间内,即客户端正在节流):

If you are applying restrictions on the number of requests per hour/day, the 429 status code may be suitable for your needs (however this status code is used by a server to indicate that too many requests have been received in a short amount of time, that is, the client is throttling):

4. 429请求太多

429状态码表示用户发送了太多 在给定的时间内请求(速率限制").

The 429 status code indicates that the user has sent too many requests in a given amount of time ("rate limiting").

响应表示应包括详细说明 条件,并且可以包含 Retry-After 标头,指示需要多长时间 等待,然后再发出新请求.

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.

例如:

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>

请注意,此规范未定义原始服务器的方式 标识用户,也不标识其计数请求的方式.例如, 限制请求速率的原始服务器可以基于 整个服务器中每个资源的请求数, 甚至是一组服务器之间.同样,它可以识别用户 通过其身份验证凭据或有状态Cookie.

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.

状态码为429的响应不得由高速缓存存储.

Responses with the 429 status code MUST NOT be stored by a cache.

HTTP状态代码是可扩展的.如果上述状态代码不符合您的需求,则可以创建自己的状态.由于这是客户端错误,因此新状态代码应位于 4xx 范围.

The 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 range.

这篇关于达到许可证限制的HTTP状态代码是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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