Download the PHP package infinitypaul/idempotency-laravel without Composer
On this page you can find all versions of the php package infinitypaul/idempotency-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download infinitypaul/idempotency-laravel
More information about infinitypaul/idempotency-laravel
Files in infinitypaul/idempotency-laravel
Package idempotency-laravel
Short Description Elegant and production-ready idempotency middleware for Laravel APIs.
License MIT
Informations about the package idempotency-laravel
Idempotency for Laravel
A production-ready Laravel middleware for implementing idempotency in your API requests. Safely retry API calls without worrying about duplicate processing.
What Is Idempotency?
Idempotency ensures that an API operation produces the same result regardless of how many times it is executed. This is critical for payment processing, order submissions, and other operations where duplicate execution could have unintended consequences.
Features
- Robust Cache Mechanism: Reliably stores and serves cached responses
- Lock-Based Concurrency Control: Prevents race conditions with distributed locks
- Comprehensive Telemetry: Track and monitor idempotency operations
- Alert System: Get notified about suspicious activity
- Payload Validation: Detect when the same key is used with different payloads
- Detailed Logging: Easily debug idempotency issues
Installation
You can install the package via composer:
Configuration
This will create a config/idempotency.php file with the following options:
Usage
Add the middleware to your routes or route groups in your routes/api.php file:
Using With Requests
To make an idempotent request, clients should include an Idempotency-Key header with a unique UUID:
If the same idempotency key is used again with the same payload, the original response will be returned without re-executing the operation.
Response Headers
The middleware adds these headers to responses:
Idempotency-Key
: The key used for the requestIdempotency-Status
: EitherOriginal
(first request) orRepeated
(cached response)
Telemetry
The package provides built-in telemetry through various service. The telemetry records:
- Request processing time
- Cache hits and misses
- Lock acquisition time
- Response sizes
- Error rates
Telemetry Drivers
I intend to add more drivers in my free time
- Inspector (https://inspector.dev/)
Custom Driver
To use a custom telemetry driver, implement the TelemetryDriver interface:
Then update your configuration:
Advanced Usage
Custom Events
The package dispatches an events that you can listen for:
All versions of idempotency-laravel with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/events Version ^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0
inspector-apm/inspector-laravel Version ^4.11