PHP code example of avnsh1111 / laravel-api-rate-limiter

1. Go to this page and download the library: Download avnsh1111/laravel-api-rate-limiter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

avnsh1111 / laravel-api-rate-limiter example snippets


'providers' => [
    // ...
    Avnsh1111\LaravelApiRateLimiter\LaravelApiRateLimiterServiceProvider::class,
],

return [
    'default_limit' => 60, // default number of requests allowed per minute

    'rate_limit_by' => 'ip', // rate limit by 'ip', 'user', or 'route'

    'response_headers' => true, // t' => [
        'ips' => [], // IP addresses to blacklist
        'users' => [], // User IDs to blacklist
        'routes' => [], // Route names to blacklist
    ],

];

use Avnsh1111\LaravelApiRateLimiter\Middleware\RateLimiter;

Route::middleware([RateLimiter::class])->group(function () {
    Route::get('/api/endpoint', 'ApiController@index');
});

Route::get('/api/endpoint', 'ApiController@index')->middleware(RateLimiter::class . ':100'); // 100 requests per minute
bash
php artisan vendor:publish --provider="Avnsh1111\LaravelApiRateLimiter\LaravelApiRateLimiterServiceProvider"