HTTP API速率限制HTTP响应标头的示例

M8R*_*w5r 73 api rest http rate-limiting http-status-code-429

其中一个附加HTTP状态代码(RFC6585)是

在哪里可以找到对此HTTP响应状态有用的HTTP/REST API速率限制HTTP响应头的示例?

M8R*_*w5r 118

以下是HTTP API速率限制HTTP响应标头的一些示例.取自四个常见的REST API:Github,Vimeo,Twitter和Imgur:

Github速率限制http://developer.github.com/v3/#rate-limiting

#=============================#=============================================#
# HTTP Header                 # Description                                 #
#=============================#=============================================#
| X-RateLimit-Limit           | Request limit per hour                      |
+-----------------------------+---------------------------------------------+
| X-RateLimit-Remaining       | The number of requests left for the time    |
|                             | window                                      |
+-----------------------------+---------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

Vimeo速率限制http://developer.vimeo.com/guidelines/rate-limiting

#=============================#=============================================#
# HTTP Header                 # Description                                 #
#=============================#=============================================#
| X-RateLimit-Limit           | Request limit per day / per 5 minutes       |
+-----------------------------+---------------------------------------------+
| X-RateLimit-Remaining       | The number of requests left for the time    |
|                             | window                                      |
+-----------------------------+---------------------------------------------+
| X-RateLimit-Reset           | The remaining window before the rate limit  |
|                             | resets in UTC epoch seconds                 |
+-----------------------------+---------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

Twitter REST API速率限制https://dev.twitter.com/docs/rate-limiting/1.1

注意: Twitter使用类似名称的标题,如Vimeo,但每个名称中都有另一个短划线.

#=============================#=============================================#
# HTTP Header                 # Description                                 #
#=============================#=============================================#
| X-Rate-Limit-Limit          | The rate limit ceiling for that given       |
|                             | request                                     |
+-----------------------------+---------------------------------------------+
| X-Rate-Limit-Remaining      | The number of requests left for the         |
|                             | 15 minute window                            |
+-----------------------------+---------------------------------------------+
| X-Rate-Limit-Reset          | The remaining window before the rate limit  |
|                             | resets in UTC epoch seconds                 |
+-----------------------------+---------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

Imgur API速率限制http://api.imgur.com/

#=============================#=============================================#
# HTTP Header                 # Description                                 #
#=============================#=============================================#
| X-RateLimit-UserLimit       | Total credits that can be allocated         |
+-----------------------------+---------------------------------------------+
| X-RateLimit-UserRemaining   | Total credits available                     |
+-----------------------------+---------------------------------------------+
| X-RateLimit-UserReset       | Timestamp (unix epoch) for when the credits |
|                             | will be reset                               |
+-----------------------------+---------------------------------------------+
| X-RateLimit-ClientLimit     | Total credits that can be allocated for the |
|                             | application in a day                        |
+-----------------------------+---------------------------------------------+
| X-RateLimit-ClientRemaining | Total credits remaining for the application |
|                             | in a day                                    |
+-----------------------------+---------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

  • 如果您正在设计自己的速率限制标头,则最佳当前实践BCP178是相关资源,建议不要弃用X-前缀.查看原始RFC/BCP以获取更多信息.http://tools.ietf.org/html/bcp178 (8认同)

Rae*_*ald 25

除了API特定的标题之外,不要忘记简单的标准Retry-After标题.

  • 429请求太多:"响应表示应该包括解释条件的详细信息,并且可以包含一个Retry-After标头,指示在发出新请求之前需要等待多长时间." https://tools.ietf.org/html/rfc6585#section-4 (15认同)
  • @Russbear但该部分中没有任何内容表明它不能与其他响应代码一起使用. (3认同)
  • `Retry-After` 旨在与 `503` 或 `30x` 响应一起使用 https://tools.ietf.org/html/rfc7231#section-7.1.3 (2认同)