Installation
Install via Composer
composer require bluebeetle/idempotency-middleware
The service provider is auto-discovered by Laravel — no manual registration needed.
Publish Configuration
php artisan vendor:publish --tag=bluebeetle-idempotency-config
This creates config/bluebeetle/idempotency.php:
return [
'main_header_name' => env('IDEMPOTENCY_MAIN_HEADER', 'Idempotency-Key'),
'repeated_header_name' => env('IDEMPOTENCY_REPEATED_HEADER', 'Idempotent-Replayed'),
'expiration_time' => env('IDEMPOTENCY_EXPIRATION_TIME', 360), // minutes
'http_methods' => ['POST', 'PUT', 'PATCH', 'DELETE'],
];
Register the Middleware
Add the middleware to your API routes:
use BlueBeetle\IdempotencyMiddleware\Idempotency;
Route::middleware([Idempotency::class])->group(function () {
Route::post('/orders', [OrderController::class, 'store']);
Route::put('/orders/{order}', [OrderController::class, 'update']);
});
Or apply it globally to all API routes in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->api(append: [
\BlueBeetle\IdempotencyMiddleware\Idempotency::class,
]);
})