当前位置:网站首页>Restful API current limiting

Restful API current limiting

2021-02-23 18:06:40 goalidea

RESTful API Current limiting

translation Rate limiting your RESTful API

Current limiting : Use X-RateLimit-*HTTP Head and 429 Status code

When your API When widely used by applications and users , Current limiting has become necessary .

After the current limit is reached , Your API We should return to the following HTTP The status code :

429 Too Many Requests

But unfortunately ,HTTP Header has no standard name , You can use the standard header to inform the user of the current limitation :

Twitter Use the following header :

  • X-Rate-Limit-Limit - The endpoint The upper limit of the upper limit flow
  • X-Rate-Limit-Remaining - 15 Number of requests remaining in minutes
  • X-Rate-Limit-Reset - With UTC Seconds per unit , Time remaining before current limiting reset

Github Use the following header :

  • X-RateLimit-Limit - The maximum number of requests you are allowed to make per hour .
  • X-RateLimit-Remaining - The number of requests remaining in the current flow limit .
  • X-RateLimit-Reset - With UTC Seconds per unit , The reset time of the current current limiter .

however , Use Github The standard seems to be better than using Twitter The standard of RESTful API More frames , That's why I suggest you use Github Of HTTP Header for current limiting ( namely X-RateLimit-Limit,X-RateLimit-Remaining and X-RateLimit-Reset), There is only one exception .

Do not use Github Standards for X-RateLimit-Reset header . You can keep the same header name , But don't show the timestamp in the value of this header , Instead, the number of seconds remaining before the current limiting reset should be displayed .

Why? ? because HTTP The specification states that the date format should use RFC 1123( namely : Friday ,2018 year 3 month 9 Japan 08:50:15 GMT). therefore , If you want to in X-RateLimit-Reset The date is displayed in the header , You should use this format instead of a timestamp , But it's more practical to use the remaining seconds .

版权声明
本文为[goalidea]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/02/20210223180524793X.html

随机推荐