Search by

roundly-consulting / http-client-rate-limits-for-laravel

mihaliak

Rate limit outgoing requests made with Laravel's HTTP client

Package info

github.com/roundly-consulting/http-client-rate-limits-for-laravel

pkg:composer/roundly-consulting/http-client-rate-limits-for-laravel

Fund package maintenance!

Patreon

Statistics

Installs: 42

Dependents: 5

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 17:54 UTC

This package is auto-updated.

Last update: 2026-10-03 18:04:25 UTC


README

HTTP Client Rate Limits for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

HTTP Client Rate Limits for Laravel

Rate limit the outgoing requests you make with Laravel's HTTP client, so you never blow past a third-party API's quota. When a budget is spent the request waits for the next free slot instead of earning a 429; compound windows, per-owner budgets, server-adaptive limits and shared stores come built in.

Installation

Requires PHP 8.4 and Laravel 12 or 13.

composer require roundly-consulting/http-client-rate-limits-for-laravel

The default InMemoryStore counts per process. With several workers, share one budget by setting HTTP_CLIENT_RATE_LIMITS_STORE to the CacheStore, RedisStore or DatabaseStore class (the last one needs its tables: php artisan vendor:publish --tag="http-client-rate-limits-migrations", then migrate).

Usage

Throttle any HTTP client call with the rateLimit() macro and the RateLimits facade:

use Illuminate\Support\Facades\Http;
use RoundlyConsulting\HttpClientRateLimits\Facades\RateLimits;

// 5 requests per second; the sixth waits for a free slot, then goes out.
Http::rateLimit(RateLimits::perSecond(5))->get('https://api.example.com/things');

// 30 per minute, with a separate budget per account.
Http::rateLimit(30, by: 'acct-1')->get('https://api.example.com/orders');

Combine windows, follow the server's own limits and cap the wait:

$limit = RateLimits::perSecond(5)
    ->alongside(RateLimits::perMinute(100))   // both windows apply; the strictest wins
    ->adaptive()                              // honour Retry-After / X-RateLimit-* headers
    ->maxWait(5_000);                         // throw RateLimitExceededException past 5 s

Http::rateLimit($limit)->get('https://api.example.com/report');

$limit->remaining();                          // requests left in the window, without sending one

Documentation

The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/http-client-rate-limits-for-laravel

Release notes are in CHANGELOG.md. To contribute, see the contributing guide.

Support our work

This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

The MIT License (MIT). Please see License File for more information.