Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

Laravel Throttle Middleware: How to Increase API Rate Limit Safely and for 429 Too Many Requests

If you’re working with Laravel APIs, you might have encountered this default throttle setting:

'api' => [
    'throttle:60,1',
    'bindings',
],

This line lives in your app/Http/Kernel.php file and controls how many requests a user can make to your API. In this blog post, we’ll explore what it means, why you might want to change it, and how to safely increase the rate limit for your Laravel application.


🧠 What Does 'throttle:60,1' Mean?

This throttle rule applies a rate limit to all API requests:

  • 60 = number of requests allowed
  • 1 = time in minutes

🔁 In short:

Each user (or IP) can make 60 requests per minute to your API.


🚫 Why You Might Want to Change It

You may want to increase the throttle limit if:

  • Your frontend app sends many background requests.
  • You’re integrating with another system (like a mobile app or a microservice).
  • Users are getting 429 Too Many Requests errors frequently.

✅ How to Increase the Throttle Value

To change the limit, go to:

app/Http/Kernel.php

Find this section:

protected $middlewareGroups = [
    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];

Change it to something like:

'api' => [
    'throttle:200,1', // Allow 200 requests per minute
    'bindings',
],

Tip:

You can adjust this as needed, for example:

  • 'throttle:100,1' → 100 req/min
  • 'throttle:500,5' → 500 requests every 5 minutes

🎯 Apply Custom Throttle to Specific Routes (Optional)

If you don’t want to increase the throttle globally, you can apply it to specific routes like this:

Route::middleware(['auth:api', 'throttle:300,1'])->get('/profile', function () {
    return response()->json(['user' => auth()->user()]);
});

Or create a group:

Route::middleware(['auth:api', 'throttle:500,5'])->group(function () {
    Route::get('/orders', 'OrderController@index');
    Route::get('/products', 'ProductController@index');
});

Bonus: Create Named Custom Throttle

In RouteServiceProvider.php:

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;

public function boot()
{
    RateLimiter::for('custom-api', function ($request) {
        return Limit::perMinute(300)->by($request->ip());
    });
}

Then in routes:

Route::middleware(['throttle:custom-api'])->get('/my-endpoint', 'MyController@method');

Laravel makes it easy to control your API traffic using the throttle middleware. If you’re experiencing issues like 429 Too Many Requests, just increasing the limit in Kernel.php or applying custom route-level throttling can solve your problem efficiently.

Related Posts

Is SonarQube Community free Edition Good for Laravel Projects?

When working on web development projects using Laravel, JavaScript, and jQuery, maintaining code quality becomes just as important as building features. That’s where tools like SonarQube come…

Fixing MySQL Error: Incorrect Definition of mysql.column_stats Table

The Problem While working on your MySQL server, you might come across this error in your error log: This error usually shows up after an upgrade or…

Fixing Laravel Migration Error: “Unknown Collation: utf8mb4_0900_ai_ci”

While working with Laravel and MySQL, you might run into an error during migrations like this one: Why This Happens The collation utf8mb4_0900_ai_ci is introduced in MySQL…

Why Dental Surgery Is Good and Important

Dental health plays a vital role in our overall well-being, yet it’s often overlooked until problems become serious. Dental surgery is a powerful solution that not only…

How to Get Cosmetic Surgery Covered by Insurance

Cosmetic surgery has become increasingly popular for individuals seeking to enhance their appearance or correct certain physical issues. While many people assume that cosmetic procedures are always…

Real-Time Memory Monitoring in Linux with free -m and watch

When your Linux system starts slowing down, the first suspect is usually memory. Is RAM maxing out? Is swap being used? Is some process eating up everything?…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x