How do I limit frequent API calls by clients?

Source: Internet
Author: User
How do I limit frequent API calls by clients? There is an http interface on the server. the client initiates a post or get request to call this interface to obtain some data. To restrict the client from initiating requests too frequently, I need to initiate the request at least 60 seconds. Now, I want to record the time when the request was initiated, and then compare the time between the current call and the last call. a status code is returned in less than 60 seconds. In addition to this method, are there other simpler methods? For example, set Apache on the server. thank you for your guidance.


Reply to discussion (solution)

Nothing is simpler than this.
Because you cannot serve only one user. if you limit the service frequency (for example, limit the Apache response)
If there are ten clients, the tenth client will receive a response 10 minutes after the first client request.
This is obviously unreasonable.

Nothing is simpler than this.
Because you cannot serve only one user. if you limit the service frequency (for example, limit the Apache response)
If there are ten clients, the tenth client will receive a response 10 minutes after the first client request.
This is obviously unreasonable.

Access interface: use memcache or redis to record an identifier (such as ip address or user ID) and set the expiration time, such as 60 seconds. when you access the interface next time, you can determine whether this value exists. If no value exists, access is allowed, yes, it indicates that it has not expired, and no access is returned. the memory record should be faster.

I have never touched anything mentioned above. First, let's take a look.

I have never touched anything mentioned above. First, let's take a look.

If you have to implement the function, the third floor provides a good solution.

Write user access interface events to logs and apply corresponding restrictions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.