https://github.com/javidalpe/laravel-idempotency
Laravel Idempotency Middleware
https://github.com/javidalpe/laravel-idempotency
api cache idempotency idempotent laravel middleware rest
Last synced: 3 months ago
JSON representation
Laravel Idempotency Middleware
- Host: GitHub
- URL: https://github.com/javidalpe/laravel-idempotency
- Owner: javidalpe
- License: mit
- Created: 2018-02-23T20:23:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-01T03:45:07.000Z (over 5 years ago)
- Last Synced: 2025-06-08T16:03:24.771Z (4 months ago)
- Topics: api, cache, idempotency, idempotent, laravel, middleware, rest
- Language: PHP
- Size: 7.81 KB
- Stars: 26
- Watchers: 1
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Idempotent Requests
First, what is Idempotency and why I need it?
Checkout this awesome [post from Brandum Leach](https://stripe.com/blog/idempotency).
### Install
Require this package with composer using the following command:
```bash
composer require javidalpe/laravel-idempotency
```### Usage
Register Idempotency middleware on your http kernel file:
```php
'api' => [
'throttle:60,1',
'bindings',
\Javidalpe\Idempotency\Idempotency::class,
],
```To perform an idempotent request, provide an additional `Idempotency-Key: ` header to the request.
### How it works
If the header `Idempotency-Key` is present on the request and the request method is different from GET, PUT and DELETE, the middleware stores the response on the cache. Next time you make a request with same idempotency key, the middleware will return the cached response.
How you create unique keys is up to you, but I suggest using V4 UUIDs or another appropriately random string. It'll always send back the same response for requests made with the same key, and keys can't be reused with different request parameters. Keys expire after 24 hours.
### License
The Laravel Idempotency is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)