danielebuso/idempotency

There is no license information available for the latest version (1.0.1) of this package.

An easily customisable and reusable idempotency middleware for Laravel.

1.0.1 2020-03-16 13:22 UTC

This package is auto-updated.

Last update: 2024-11-17 00:24:34 UTC


README

Latest Version on Packagist Software License Total Downloads

A super simple, customisable and automatically registering middleware to help you ensure your requests are Idempotent when it’s required.

Inspired by the guys at Stripe https://stripe.com/blog/idempotency and the realisation of how important this little feature is I mocked up this package.

Features

The idempotency layer compares incoming parameters to those of the original request and errors unless they're the same to prevent accidental misuse.

Once installed you can do stuff like this:

// Adding idempotency layer to a route
Route::post('hello-world', function() {
    // stuff
})->middleware('idempotent');

Installation

You can install the package via composer:

composer require danielebuso/idempotency

Customization

You can publish the package config by running:

php artisan vendor:publish --provider="idempotency\ServiceProvider"

You can also customize idempotency methods to other than POST, however it should be noted that:

According to HTTP semantics, the PUT and DELETE verbs are idempotent, and the PUT verb in particular signifies that a target resource should be created or replaced entirely with the contents of a request’s payload.