PHPackages                             eufaturo/idempotency-middleware - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. eufaturo/idempotency-middleware

ActiveLibrary[HTTP &amp; Networking](/categories/http)

eufaturo/idempotency-middleware
===============================

Idempotency middleware for your Laravel API.

v1.0.0(11mo ago)3730[2 issues](https://github.com/eufaturo/idempotency-middleware/issues)[1 PRs](https://github.com/eufaturo/idempotency-middleware/pulls)MITPHPPHP ^8.3CI passing

Since Jun 13Pushed 1mo ago2 watchersCompare

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

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

Idempotency Middleware for Laravel
==================================

[](#idempotency-middleware-for-laravel)

[![GitHub Tests Action Status](https://github.com/eufaturo/idempotency-middleware/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/eufaturo/idempotency-middleware/actions?query=workflow%3Atests)[![GitHub Code Analysis Action Status](https://github.com/eufaturo/idempotency-middleware/actions/workflows/code-analysis.yml/badge.svg?branch=main)](https://github.com/eufaturo/idempotency-middleware/actions?query=workflow%3Acode-analysis)[![Software License](https://camo.githubusercontent.com/1cf2a5ec41aed31a50264f12abb250160b73634bb5f8e6c0262a71ca16d3305a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f657566617475726f2f6964656d706f74656e63792d6d6964646c65776172653f6c6162656c3d4c6963656e7365)](https://opensource.org/licenses/MIT)[![Latest Version on Packagist](https://camo.githubusercontent.com/4b762bd43a59ae391701d3c3ef85480cdb57aac8e2280da664a3d263826eda80/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f657566617475726f2f6964656d706f74656e63792d6d6964646c65776172652e7376673f6c6162656c3d5061636b6167697374)](https://packagist.org/packages/eufaturo/idempotency-middleware)[![Total Downloads](https://camo.githubusercontent.com/944b7cbe5e1b1b35f43f530ed4001ca01932ffe6f15b8b21686328d7eab76317/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f657566617475726f2f6964656d706f74656e63792d6d6964646c65776172652e7376673f6c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/eufaturo/idempotency-middleware)

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

[](#introduction)

Simple and fully tested Laravel middleware for implementing idempotency in your API requests.

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

[](#installation)

This library is installed via [Composer](https://getcomposer.org/) and to install, run the following command:

```
composer require eufaturo/idempotency-middleware
```

The package will automatically register itself.

Configuration
-------------

[](#configuration)

You can now optionally publish the config file with:

```
php artisan vendor:publish --tag="eufaturo-idempotency-config"
```

This will create a file at `config/eufaturo/idempotency.php`, where you can adjust the header names, the TTL of the cached response, and the HTTP methods considered idempotent.

Or if you prefer, without publishing the config file, you can define the following on your `.env` file:

```
IDEMPOTENCY_MAIN_HEADER="X-Idempotency-Key"
IDEMPOTENCY_REPEATED_HEADER="X-Idempotent-Replayed"
IDEMPOTENCY_EXPIRATION=720 # 12 hours (define in minutes)
```

How to use
----------

[](#how-to-use)

To use it, just apply the middleware in your route groups or a single route.

#### Example 1

[](#example-1)

```
