eufaturo/idempotency-middleware

Idempotency middleware for your Laravel API.

dev-main / 1.0.x-dev 2025-06-09 18:33 UTC

This package is auto-updated.

Last update: 2025-06-09 18:33:58 UTC


README

GitHub Tests Action Status GitHub Code Analysis Action Status Software License Latest Version on Packagist Total Downloads

Introduction

Simple Laravel middleware for implementing idempotency in your API requests

Installation

This library is installed via Composer and to install, run the following command.

composer require eufaturo/idempotency-middleware

Usage

Apply the middleware in your routes or route groups in your, here's a simple example:

<?php

use Eufaturo\IdempotencyMiddleware\Idempotency;

Route::middleware(['auth:api', Idempotency::class])->group(function () {
    Route::post('/create-user', function () {
        // Create the user ...
    });
});

Usage with HTTP Requests

To perform an idempotent request, provide an additional Idempotency-Key header through the request options where the value should be a valid UUID v4

Example:

POST /api/create-user HTTP/1.1
Content-Type: application/json
Idempotency-Key: 6b3fd36c-24c6-4eb2-a764-bb6c91b33e56

{
  "name": "John Doe",
  "email": "john.doe@example.com",
  "password: "secret"
}

Testing

composer test

Contributing

Thank you for your interest. Here are some of the many ways to contribute.

License

This library is open-sourced software licensed under the MIT license.