laravel-api-idempotency maintained by pharaonic
Description
Opt-in HTTP idempotency for Laravel routes: Route::post(...)->idempotent() with atomic database or Redis reservation, request fingerprinting, safe response replay and fail-closed recovery.
Author
Last update
2026/11/23 22:14
(dev-develop)
License
Downloads
0
Tags
redis - rest - api - middleware - laravel - concurrency - replay - idempotency - idempotent - idempotency-key
Installation
composer require pharaonic/laravel-api-idempotency
The service provider is registered automatically. The default database store needs its table; publish the migration and run it (skip this when you only use Redis):
php artisan vendor:publish --tag=api-idempotency-migrations
php artisan migrate
Publish the configuration when you need to change it:
php artisan vendor:publish --tag=api-idempotency-config
Usage
use App\Http\Controllers\OrderController;
use App\Http\Controllers\PaymentController;
use Illuminate\Support\Facades\Route;
Route::middleware('auth:api')->group(function () {
Route::post('orders', [OrderController::class, 'store'])->idempotent();
Route::post('payments', [PaymentController::class, 'store'])->idempotent(ttl: 604800);
});
Clients send an Idempotency-Key header. A retry with the same key and request gets the stored response with Idempotency-Replayed: true; the same key with another request, or while the first one still runs, gets 409. This prevents duplicate execution of one key; it is not exactly-once delivery of external side effects.
Documentation
Full documentation: Laravel API Idempotency Documentation.
Support & Security
See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.
License
MIT. See LICENSE.