PHPackages                             algoyounes/idempotency - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. algoyounes/idempotency

ActiveLibrary[API Development](/categories/api)

algoyounes/idempotency
======================

Laravel Idempotency Middleware package to prevent duplicate requests

v1.1.1(5mo ago)251681MITPHPPHP ^8.2CI passing

Since Feb 1Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/algoyounes/laravel-idempotency)[ Packagist](https://packagist.org/packages/algoyounes/idempotency)[ RSS](/packages/algoyounes-idempotency/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (10)Used By (0)

[![Laravel Idempotency Logo](assets/logo.png)](assets/logo.png)
**Idempotency**

[![Build Status](https://github.com/algoyounes/idempotency/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/algoyounes/idempotency/actions)[![Total Downloads](https://camo.githubusercontent.com/f56dbbd74893e24b8069ee5d8e742268f317ee3b3d5f8077629bb24b97f4c601/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c676f796f756e65732f6964656d706f74656e6379)](https://packagist.org/packages/algoyounes/idempotency)[![Latest Stable Version](https://camo.githubusercontent.com/779194b037d4f5f2744de6701d4b21d96f4c5bd49b6c53962aabac7c8695dd21/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c676f796f756e65732f6964656d706f74656e6379)](https://packagist.org/packages/algoyounes/idempotency)[![License](https://camo.githubusercontent.com/cd6f7af91c2e80cd142c45a198e2e1e4e84956850f26212796559acc69c5882e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c676f796f756e65732f6964656d706f74656e6379)](https://packagist.org/packages/algoyounes/idempotency)

**Idempotency** is a Laravel package that helps you make your requests idempotent. Idempotent requests can be safely retried without causing any side effects. This is useful when you're dealing with unreliable networks or when you want to prevent duplicate requests from being processed.

Features ✨
----------

[](#features-)

- **Idempotent Requests**: Ensure that requests can be safely retried without side effects.
- **Middleware Integration**: Easily add `idempotency` middleware to routes or route groups.
- **Customizable Cache**: Configure cache TTL and store for idempotency keys.
- **Duplicate Handling**: Choose between replaying cached responses or throwing exceptions for duplicate requests.
- **Custom Resolvers**: Implement custom logic for resolving user IDs or generating cache keys.
- **Header-Based Idempotency**: Use the `Idempotency-Key` header to identify requests.
- **Race Condition Handling**: Prevent race conditions with configurable lock wait times.
- **Unauthenticated Support**: Define a default user ID name for unauthenticated requests.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require algoyounes/idempotency
```

You can publish the configuration file using the following command:

```
php artisan vendor:publish --provider="AlgoYounes\Idempotency\Providers\IdempotencyServiceProvider" --tag="config"
```

Here are the available options in the configuration file:

OptionDefault ValueDescription`enable``true`Enable or disable the idempotency middleware`cache.ttl``86400` *(1 Day)*The time-to-live for idempotency keys in minutes`cache.store``default`The cache store to use for idempotency keys`idempotency_header``Idempotency-Key`The header to use for idempotency keys`idempotency_relayed_header``Idempotency-Relayed`The header for relaying idempotency keys`duplicate_handling``replay`The action to take when a duplicate request is detected. Options are `replay` or `exception``enforced_verbs``['GET', 'POST', 'PUT', 'PATCH', 'DELETE']`The HTTP verbs to enforce idempotency on`max_lock_wait_time``10` *(10 seconds)*The maximum time to wait for a lock in seconds`user_id_resolver``null`The user ID resolver to use for generating cache keys`unauthenticated_user_id``guest`The default user ID name for unauthenticated requestsUsage
-----

[](#usage)

To request idempotent, try adding something like `idempotency` middleware to the route or group of routes you want to protect. The middleware will check if the request is idempotent by looking for the `Idempotency-Key` header. If the header is present, the middleware will cache the response and reuse it for subsequent requests with the same key.

```
Route::middleware('idempotency')->post('/orders', 'OrderController@store');
```

You can also add the middleware to a group of routes:

```
Route::middleware('idempotency')->group(function () {
    Route::post('/orders', 'OrderController@store');
    Route::get('/orders/{id}', 'OrderController@show');
});
```

Custom Resolver 🔧
-----------------

[](#custom-resolver-)

You can create your resolver by implementing the `Resolver` interface. This is useful when you want to store the cache in a different store or when you want to customize the key generation logic.

```
use AlgoYounes\Idempotency\Contracts\Resolver;

class CustomUserIdResolver implements Resolver
{
    public function resolve(): string
    {
        // Your custom logic here
    }
}

// In the configuration file
'user_id_resolver' => CustomUserIdResolver::class,
```

Contributing
------------

[](#contributing)

Thank you for considering contributing to the Idempotency package. For more details, please check the [CONTRIBUTING](CONTRIBUTING.md) file.

License
-------

[](#license)

The Idempotency package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance72

Regular maintenance activity

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~68 days

Total

9

Last Release

167d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bfd15013ece7b7782813460af6ec7162ca0d9973cc0d9cf5ef3307f5afba0b5a?d=identicon)[Algo Younes](/maintainers/Algo%20Younes)

---

Top Contributors

[![algoyounes](https://avatars.githubusercontent.com/u/45436028?v=4)](https://github.com/algoyounes "algoyounes (81 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

api-idempotentduplicate-requestidempotence-middlewareidempotencyidempotent-requestslaravellaravel-middlewareresiliency-patternsmiddlewareapilaravelidempotencylaravel-idempotencyidempotentlaravel middlewareduplicate requestsphp idempotencyprevent duplicate api requestslaravel api idempotencyhttp idempotencyduplicate submission preventionrequest throttling

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/algoyounes-idempotency/health.svg)

```
[![Health](https://phpackages.com/badges/algoyounes-idempotency/health.svg)](https://phpackages.com/packages/algoyounes-idempotency)
```

###  Alternatives

[reindert-vetter/api-version-control

A Laravel package to manage versions of endpoints in an elegant way

1671.0M](/packages/reindert-vetter-api-version-control)[square1/laravel-idempotency

Add idempotency to Laravel-based APIs, preventing duplicate request processing.

108170.6k](/packages/square1-laravel-idempotency)[imliam/laravel-throttle-simultaneous-requests

Throttle the current user's requests based on how many requests are currently being executed.

4623.0k](/packages/imliam-laravel-throttle-simultaneous-requests)[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2913.6k](/packages/shahghasiadil-laravel-api-versioning)[javidalpe/laravel-idempotency

Laravel Idempotency Middleware

2565.9k](/packages/javidalpe-laravel-idempotency)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
