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


Answers:


125

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

11
如果您要设计自己的速率限制标题,则“最佳当前实践” BCP178是相关资源,建议不要使用X-前缀。请查看原始的RFC / BCP以获取更多信息。tools.ietf.org/html/bcp178
10gistic 2014年

很好的例子,我制作了一个可以与该request包一起使用的Node.js包:github.com/webjay/x-rate
webjay 2015年

30

除了特定于API的标头外,别忘了谦虚的标准Retry-After标头

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

与503或3xx状态代码一起使用时,该标准提出了一些其他建议:

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



1
Retry-After旨在与50330x响应工具
html / rfc7231#

3
@Russbear,但该部分中没有任何内容表明它不能与其他响应代码一起使用。
Raedwald

19
429请求太多:“响应表示应包含说明条件的详细信息,并且可以包含Retry-After标头,指示在发出新请求之前要等待多长时间。” tools.ietf.org/html/rfc6585#section-4
MRA
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.