Search by

pharaonic / laravel-api-idempotency

Pharaonic

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.

13.0.0 2026-11-23 21:14 UTC

This package is auto-updated.

Last update: 2026-11-23 21:14:33 UTC


README

PHP Version : 8.3 | 8.4 | 8.5 Laravel Version : 13.x License Build
Source Packagist Version Packagist Downloads AI Ready: Laravel Boost

Opt-in Idempotency-Key handling for Laravel routes: retries replay the stored response instead of running twice.


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.