I'm fairly new to Laravel and am currently using an API that has a limit of 25 requests per minute.
I have a controller method sendRequest() which is used by all methods to send requests to the API so I was thinking this is the place to put a rate limiter that checks if the current request can be added to the queue if the limit is not yet reached.
I was thinking something like this:
protected function sendRequest(){
if ($this->allowRequest()) {
//proceed to api call
}
}
protected function allowRequest() {
$allow = false;
//probably a do-while loop to check if the limit has been reached within the timeframe?
}
I've found this class Illuminate\Cache\RateLimiter that I think could be useful but have no idea how to use it yet. Can anyone point me to the right direct with this? So basically the request should "wait" and execute only if the 25 requests/minute limit hasn't been reached.
Thanks!