Idempotency for Laravel is a production-ready package for implementing idempotency in API requests. Clients can safely retry API calls using this package without worrying about duplicate processing.
Using the Idempotency-Key
header with a unique UUID, you can send the same key over and over, and the original response is returned without running an operation multiple times:
POST /api/payments HTTP/1.1Content-Type: application/jsonIdempotency-Key: 123e4567-e89b-12d3-a456-426614174000 { "amount": 1000, "currency": "USD", "description": "Order #1234"}
When using this package, API responses include an Idempotency-Key
that API users safely use in the future to re-run the operation.
Main 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
You can learn more about this package, get full installation instructions, and view the source code on GitHub. You can install this package via Composer:
composer require infinitypaul/idempotency-laravelphp artisan vendor:publish --provider="Infinitypaul\Idempotency\IdempotencyServiceProvider"