额外的HTTP状态代码(RFC6585)之一是
在哪里可以找到可用于此HTTP响应状态的HTTP / REST API速率限制HTTP响应标头的示例?
Answers:
这是HTTP API速率限制HTTP响应标头的一些示例。取自四种常见的REST API:Github,Vimeo,Twitter和Imgur:
#=============================#=============================================#
# HTTP Header # Description #
#=============================#=============================================#
| X-RateLimit-Limit | Request limit per hour |
+-----------------------------+---------------------------------------------+
| X-RateLimit-Remaining | The number of requests left for the time |
| | window |
+-----------------------------+---------------------------------------------+
#=============================#=============================================#
# 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使用与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 |
+-----------------------------+---------------------------------------------+
#=============================#=============================================#
# 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 |
+-----------------------------+---------------------------------------------+
request
包一起使用的Node.js包:github.com/webjay/x-rate
除了特定于API的标头外,别忘了谦虚的标准Retry-After
标头
服务器发送“ Retry-After”标头字段,以指示用户代理在发出后续请求之前应等待多长时间...。此字段的值可以是HTTP日期或要延迟的秒数收到响应后。
与503或3xx状态代码一起使用时,该标准提出了一些其他建议:
当发送503(服务不可用)响应时,Retry-After指示客户端预期服务将不可用多长时间。与任何3xx(重定向)响应一起发送时,Retry-After表示在发出重定向请求之前,要求用户代理等待的最短时间。
response.headers["x-ratelimit-limit"]