midnite81 / guardian
Guardian is a PHP package that provides a way to wrap HTTP requests so they don't exceed Rate Limiting rules and controls Error Handling
Requires
- php: >8.2
Requires (Dev)
- illuminate/cache: ^11.25
- illuminate/support: ^11.25
- laravel/pint: ^1.18
- mockery/mockery: ^1.6
- nikic/php-parser: ^4.17 || ^5.0
- orchestra/testbench: ^9.5
- pestphp/pest: ^3.2
- pestphp/pest-plugin-type-coverage: ^3.0
- phpstan/phpstan: ^1.12
- spatie/ray: ^1.41
README
Guardian is a powerful and flexible rate limiting and error handling library for PHP applications. It provides a robust system for managing API rate limits, preventing abuse, and handling errors gracefully. Guardian can be used in any PHP project and has built-in support for Laravel applications. Full documentation: guardian.midnite.uk
Requirements
- PHP 8.2 or higher
Key Features
- Flexible rate limiting rules
- Configurable error handling
- Multiple cache drivers (File, Redis, Laravel)
- Ability to add custom drivers
- Easy integration with Laravel
- Customizable for any PHP project
Installation
Install Guardian via Composer:
composer require midnite81/guardian
Quick Start
use Midnite81\Guardian\Factories\GuardianFactory; use Midnite81\Guardian\Store\FileStore; use Midnite81\Guardian\Rules\RateLimitRule; $guardian = GuardianFactory::create( 'my-api', new FileStore('/path/to/cache'), [RateLimitRule::allow(100)->perMinute()] ); $result = $guardian->send(function() { // Your API logic here });
Documentation
For detailed usage instructions, API reference, and advanced configuration options, please refer to the official Guardian documentation:
Future plans for Guardian
As of October 2024, Guardian has just been released and there is no roadmap as such for it as yet. Its use in the wild might bring in required features.
Some initial thoughts:
- More integration for Laravel, but introducing a config file to make getting instances more easily
- Adding in a way to work with PSR-7, PSR-18, PSR-17, and PSR-15
Contributing
Contributions are welcome! Please see our Contributing Guide for more details.
License
Guardian is open-sourced software licensed under the MIT license.