perhaps the name may different, try inspect the response data... https://medium.com/@guillaume.viguierjust/rate-limiting-your-restful-api-3148f8e77248
May 19, 2022
5
Level 2
Trying to log API throttling
Been giving a task to put some information in the logs when a client hits their throttle limit. Have had some success making these changes in class RouteServiceProvider.php. The problem I'm facing now is that the response is missing the X-RateLimit* headers. Does anyone know how those headers are set? The getHeaders function in the ThrottleRequests appears to create the headers I need, but I'm not sure how to get the info for the function parameters.
protected function configureRateLimiting()
{
RateLimiter::for(
'api',
fn (Request $request) => Limit::perMinute(60)
->by(optional($request->user())->id ?: $request->ip())
->response(function () {
Log::info('DEBUG: Put throttle info here');
abort(429, "Too Many Attempts.");
})
);
}`
Level 50
use Illuminate\Http\Exceptions\ThrottleRequestsException;
protected function configureRateLimiting()
{
RateLimiter::for(
'api',
fn (Request $request) => Limit::perMinute(60)
->by(optional($request->user())->id ?: $request->ip())
->response(function ($request, $headers) {
Log::info('DEBUG: Put throttle info here');
abort(429, "Too Many Attempts.", $headers);
});
);
}`
1 like
Please or to participate in this conversation.