PHPackages                             osid/laravel-api-rate-limiter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. osid/laravel-api-rate-limiter

ActiveLibrary[API Development](/categories/api)

osid/laravel-api-rate-limiter
=============================

A robust API rate limiter and throttling package for Laravel.

v1.0.1(1y ago)06MITPHPPHP ^7.4 || ^8.1

Since Jun 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/osidalsaghir/laravel-api-rate-limiter)[ Packagist](https://packagist.org/packages/osid/laravel-api-rate-limiter)[ RSS](/packages/osid-laravel-api-rate-limiter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Laravel API Rate Limiter
========================

[](#laravel-api-rate-limiter)

A robust API rate limiter and throttling package for Laravel, designed to manage and control the flow of requests to your APIs, protecting against abuse and ensuring fair usage.

Installation
------------

[](#installation)

1. **Require the Package:**

    Run the following command to install the package via Composer:

    ```
    composer require osid/laravel-api-rate-limiter
    ```
2. **Publish Configuration:**

    Publish the configuration file using the artisan command:

    ```
    php artisan vendor:publish --provider="osid\ApiRateLimiter\ApiRateLimiterServiceProvider" --tag=config
    ```

    This will create a configuration file at `config/api-rate-limiter.php`.

Configuration
-------------

[](#configuration)

The `api-rate-limiter.php` configuration file allows you to define rate limits and burst settings for your API routes. Here’s an example configuration:

```
return [
    'global' => [
        'limit' => 1000, // Requests per hour
        'burst' => 50, // Burst limit
    ],
    'routes' => [
        'api/v1/users' => [
            'limit' => 500,
            'burst' => 20,
        ],
        'api/v1/orders' => [
            'limit' => 200,
            'burst' => 10,
        ],
    ],
    'user_based' => true, // Enable user-specific limits
    'ip_based' => true, // Enable IP-based limits
    'cache_driver' => 'redis', // Cache driver to use
    'response_messages' => [
        'rate_limit_exceeded' => 'Too many requests. Please try again later.',
    ],
];
```

- **Global Settings:**

    - `limit`: The maximum number of requests allowed per hour globally.
    - `burst`: Additional requests allowed in short bursts.
- **Route-Specific Settings:**

    - Define limits and burst settings for specific routes.
- **User-Based and IP-Based Limits:**

    - `user_based`: Enable rate limits based on authenticated users.
    - `ip_based`: Enable rate limits based on client IP addresses.
- **Cache Driver:**

    - `cache_driver`: Specify the cache driver to use (e.g., `redis`, `memcached`).
- **Response Messages:**

    - Customize the response message when the rate limit is exceeded.

Applying Middleware
-------------------

[](#applying-middleware)

To apply the rate limiting middleware to your API routes, add it to the routes in your `routes/api.php` file.

```
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\OrderController;

Route::middleware(['api.rate.limiter'])->group(function () {
    Route::get('/users', [UserController::class, 'index']);
    Route::get('/orders', [OrderController::class, 'index']);
    // Other routes
});
```

Example Usage
-------------

[](#example-usage)

1. **Global Rate Limiting:**

    To apply global rate limits, ensure the `global` configuration is set in `config/api-rate-limiter.php`. This will apply to all routes not specifically configured.
2. **Route-Specific Rate Limiting:**

    To apply rate limits to specific routes, define them under the `routes` key in `config/api-rate-limiter.php`.

```
'api/v1/users' => [
    'limit' => 500,
    'burst' => 20,
],
'api/v1/orders' => [
    'limit' => 200,
    'burst' => 10,
],
```

3. **Custom Response Messages:**

    Customize the message returned when the rate limit is exceeded by modifying the `response_messages` key in the configuration.

```
'response_messages' => [
    'rate_limit_exceeded' => 'Too many requests. Please try again later.',
],
```

Testing
-------

[](#testing)

Use tools like Postman or cURL to test the rate limiting functionality. Make several requests to your API endpoints to ensure the rate limits and burst settings are working as expected.

Conclusion
----------

[](#conclusion)

This package provides a flexible and powerful way to manage API request rates in Laravel applications, ensuring fair usage and protecting against abuse. For any issues or contributions, please refer to the package repository.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

705d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d04c3ab9b58b0b96d94a39836e8dc5c4599d60f6291061922b718e512e9c1736?d=identicon)[osidalsaghir](/maintainers/osidalsaghir)

---

Top Contributors

[![osidalsaghir](https://avatars.githubusercontent.com/u/36995193?v=4)](https://github.com/osidalsaghir "osidalsaghir (5 commits)")

### Embed Badge

![Health badge](/badges/osid-laravel-api-rate-limiter/health.svg)

```
[![Health](https://phpackages.com/badges/osid-laravel-api-rate-limiter/health.svg)](https://phpackages.com/packages/osid-laravel-api-rate-limiter)
```

###  Alternatives

[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.1M28](/packages/mollie-laravel-mollie)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[spatie/laravel-route-discovery

Auto register routes using PHP attributes

23645.0k2](/packages/spatie-laravel-route-discovery)[esign/laravel-conversions-api

A laravel wrapper package around the Facebook Conversions API

69145.4k](/packages/esign-laravel-conversions-api)[didww/didww-api-3-php-sdk

PHP SDK for DIDWW API 3

1218.2k](/packages/didww-didww-api-3-php-sdk)[surface/laravel-webfinger

A Laravel package to create an ActivityPub webfinger.

113.8k](/packages/surface-laravel-webfinger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
