I write a lot of APIs for retrieving and storing data.
I like the default throttle option:
protected $middlewareGroups = [ 'api' => [ 'throttle:60,1', 'bindings', ], ];
to limit the request to 60 per minute; but for some route (es: POST ) I would like to increase this value.
I tried installing 'throttle:500,1' on the route middleware, as shown below:
Route::group(function () { Route::get('semaphore/1', ['uses' => 'App\Api\V1\DBs\ SemaphoreController@index ']); Route::post('semaphore/1', ['uses' => 'App\Api\V1\DBs\ SemaphoreController@store ', 'middleware' => 'WriteToDatabaseMiddleware', 'throttle:500,1']); });
but that will not work.
Any idea?
Thanks.
UPDATE:
I noticed that the 'throttle:500,1' used in the api.php route will be installed AFTER the default 'throttle:60,1' specified in the Kernel.php file; then it does not work.
When registering the execution of a process, the first call:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
from Kernel.php has maxAttempts=60 .
Then the second call:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
from api.php has maxAttempts=500 .
In other words, throttle:500,1 in the throttle:500,1 file api.php not override throttle:60,1 in the Kernel.php file.
vlauciani
source share