PHPackages                             sobhanatar/idempotent - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sobhanatar/idempotent

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sobhanatar/idempotent
=====================

Idempotent Package for Laravel

0.2(4y ago)54951MITPHPPHP ~7.4|~8

Since Nov 17Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (3)Versions (5)Used By (0)

Introduction
------------

[](#introduction)

Idempotent package provides [idempotency](https://restfulapi.net/idempotent-rest-apis/) for your laravel package. However, in its current state, maybe not extendable to different requirements and can be used as a sample of doing so. Moreover, this package will be updated, in attempt to giving more control over various aspects of it.

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

[](#installation)

To get started, install the Idempotent package via the Composer package manager:

```
$ composer require sobhanatar/idempotent
```

Idempotent service provider registers its own config, language, and database migration file, so you need to export them

```
$ php artisan vendor:publish --provider="Sobhanatar\Idempotent\IdempotentServiceProvider"
```

**Note:** If you don't want to use mysql database as shared memory, you can publish config, and language file using following command:

```
$ php artisan vendor:publish --tag=idempotent-config --tag=idempotent-language
```

Deploying Idempotent
--------------------

[](#deploying-idempotent)

To use idempotent package, you need set the options as per the need of your service in configuration and language files. The configuration file is self-documented so that you can find your way through.

The next step is deciding on how you want to control the idempotency of your service. Idempotent package provides two middlewares that can help you achieve the idempotency; `IdempotentHeader`, and `VerifyIdempotent`. Don't forget to register the middleware in `Kernel.php`.

### IdempotentHeader

[](#idempotentheader)

`IdempotentHeader` makes an idempotent key/hash based on the entity's configurations and put it in the header of request. The assumption in this middleware is that the developer will remain responsible for the logic of using the idempotent header.

### VerifyIdempotent

[](#verifyidempotent)

`VerifyIdempotent` handles all the required steps for making an endpoint idempotent. The steps are as follows:

1. Get the `entity` configuration
2. Create an idempotent key/hash based on the entity's configurations.
3. Check if the idempotent key/hash exists in the selected `storage`.
4. If it doesn't exist:
    1. A new record with the status of `progress` be created with the entity's `timeout,` and it continues to the logic of the service
    2. When code execution has finished, the response to the client updates the `status` and `response` of the cache.
5. If it exists:
    1. If the `status` is `done` or `fail`, then the `response` will be read from storage and replied to the user.
    2. If the `status` is `progress`, the message in `idempotent` language file for that `entity` will be return as response to the user.

Note: Make sure to use any of two middlewares to only those routes that you want to be idempotent, and not all the routes.

Purging Idempotent Keys/Hashes
------------------------------

[](#purging-idempotent-keyshashes)

If you use `mysql` as the storage, it's important to purge the expired keys/hashes. Idempotent included `idempotent:purge` Artisan command can do this for you.

```
# Purge expired keys/hashes
$ php artisan idempotent:purge --entity=my-idempotent-endpoint
```

You may also configure a scheduled job in your application's `App\Console\Kernel` class to automatically prune your tokens on a schedule:

```
/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('idempotent:purge')->hourly();
}
```

Under the hood
--------------

[](#under-the-hood)

This package is relied on [php-lock/lock](https://github.com/php-lock/lock) for locking mechanism and also [spatie/async](https://github.com/spatie/async) for testing the locking mechanism.

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Thank you for considering contributing to Idempotent! You can read the contribution guide [here](CONTRIBUTING.md).

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sobhan Atar](https://github.com/sobhanatar)

License
-------

[](#license)

Idempotent is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~5 days

Total

2

Last Release

1636d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c091b75953129ab82274313d82d9a8671f471a06fa02b36a16d729abd2527f0?d=identicon)[sobhanatar](/maintainers/sobhanatar)

---

Top Contributors

[![sobhanatar](https://avatars.githubusercontent.com/u/1507325?v=4)](https://github.com/sobhanatar "sobhanatar (92 commits)")

---

Tags

idempotencyidempotentidempotent-requestslaravelidempotencyidempotentIdempotent-requestIdempotent-Laravel

### Embed Badge

![Health badge](/badges/sobhanatar-idempotent/health.svg)

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

###  Alternatives

[bandwidth-throttle/token-bucket

Implementation of the Token Bucket algorithm.

5121.9M10](/packages/bandwidth-throttle-token-bucket)[lidongyooo/laravel-idempotent

laravel idempotent

132.2k](/packages/lidongyooo-laravel-idempotent)

PHPackages © 2026

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