I have the following error message in my console:
Failed to load resource: the server responded with a status of 429 (Too Many Requests)
So, my question is, from where can I get the number of requests to check and log when I'm close to the limit ?
x-ratelimit-limit: 60
x-ratelimit-remaining: 59
if you send requests by axios
axios.get(`/api/users`)
.then(({ data, headers }) => {
console.log(headers['x-ratelimit-limit']);
});
php artisan make:middleware LogRequestLimit
register it in app\Http\Kernel.php
protected $middleware = [
...
\App\Http\Middleware\LogRequestLimit::class,
];
app\Http\Middleware\LogRequestLimit.php
<?php
namespace App\Http\Middleware;
use Closure;
class LogRequestLimit
{
public function handle($request, Closure $next)
{
$response = $next($request);
\Log::debug($response->headers->get('x-ratelimit-limit'));
return $response;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With