89

附加 HTTP 状态代码 ( RFC6585 ) 之一是

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

4

2 回答 2

140

以下是 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                                      |
+-----------------------------+---------------------------------------------+

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                 |
+-----------------------------+---------------------------------------------+

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                 |
+-----------------------------+---------------------------------------------+

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                                    |
+-----------------------------+---------------------------------------------+
于 2013-04-15T18:49:30.503 回答
34

除了 API 特定的标头之外,不要忘记不起眼的标准Retry-After标头

服务器发送“Retry-After”标头字段来指示用户代理在发出后续请求之前应该等待多长时间...。该字段的值可以是 HTTP 日期或延迟秒数收到回复后。

该标准在将其与 503 或 3xx 状态代码一起使用时提出了具体的附加建议:

当与 503(服务不可用)响应一起发送时,Retry-After 指示服务预计对客户端不可用的时间。当与任何 3xx(重定向)响应一起发送时,Retry-After 指示在发出重定向请求之前要求用户代理等待的最短时间。

于 2013-05-24T14:22:48.717 回答