PHPackages                             riskio/idempotency-module - 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. riskio/idempotency-module

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

riskio/idempotency-module
=========================

Zend Framework module ensuring at most once requests for mutating endpoints.

v1.0.0(8y ago)114[1 issues](https://github.com/RiskioFr/idempotency-module/issues)MITPHPPHP ^7.0

Since Sep 27Pushed 8y ago2 watchersCompare

[ Source](https://github.com/RiskioFr/idempotency-module)[ Packagist](https://packagist.org/packages/riskio/idempotency-module)[ Docs](https://github.com/RiskioFr/idempotency-module)[ RSS](/packages/riskio-idempotency-module/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (13)Versions (2)Used By (0)

Idempotency module for Zend Framework
=====================================

[](#idempotency-module-for-zend-framework)

Zend Framework module ensuring at most once requests for mutating endpoints.

[![Latest Stable Version](https://camo.githubusercontent.com/c26c3dc1a90b394dbf2a50480e2b4cf6a4d979a304dd3ea7754f8c5df23e5764/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269736b696f2f6964656d706f74656e63792d6d6f64756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riskio/idempotency-module)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/26ba46cec382bceef6dedc1f577dc5656c89cddec2689796773612dcdaac4211/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5269736b696f46722f6964656d706f74656e63792d6d6f64756c652e7376673f7374796c653d666c61742d737175617265)](http://travis-ci.org/RiskioFr/idempotency-module)[![Total Downloads](https://camo.githubusercontent.com/bb8b78ca0b5daa9630cd9731a4a12edbc1ba6da1a1aacbc2e04ca6c38885a2ca/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7269736b696f2f6964656d706f74656e63792d6d6f64756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riskio/idempotency-module)

While the inherently idempotent HTTP semantics around PUT and DELETE are a good fit for many API calls, what if we have an operation that needs to be invoked exactly once and no more? An example might be if we were designing an API endpoint to charge a customer money; accidentally calling it twice would lead to the customer being double-charged, which is very bad.

This is where *idempotency keys* come into play. When performing a request, a client generates a unique ID to identify just that operation and sends it up to the server along with the normal payload. The server receives the ID and correlates it with the state of the request on its end. If the client notices a failure, it retries the request with the same ID, and from there it’s up to the server to figure out what to do with it.

Stripe describes its solution in a [blog post](https://stripe.com/blog/idempotency) which provided the inspiration for this package.

Requirements
------------

[](#requirements)

- PHP 7.0+
- [symfony/cache ^3.0](https://github.com/symfony/cache)
- [zendframework/zend-diactoros ^1.1](https://github.com/zendframework/zend-diactoros)
- [zendframework/zend-eventmanager ^2.6.3 || ^3.0](https://github.com/zendframework/zend-eventmanager)
- [zendframework/zend-http ^2.6](https://github.com/zendframework/zend-http)
- [zendframework/zend-mvc ^3.0](https://github.com/zendframework/zend-mvc)
- [zendframework/zend-psr7bridge ^1.0](https://github.com/zendframework/zend-psr7bridge)
- [zendframework/zend-stdlib ^2.7.3 || ^3.0](https://github.com/zendframework/zend-stdlib)
- [zendframework/zend-validator ^2.0](https://github.com/zendframework/zend-validator)

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

[](#installation)

Idempotency module only officially supports installation through Composer. For Composer documentation, please refer to [getcomposer.org](http://getcomposer.org/).

You can install the module from command line:

```
$ composer require riskio/idempotency-module
```

After installation of the package, you have to copy the `riskio_idempotency.global.php.dist` file into your `config/autoload` folder and apply any setting you want.

- source: `vendor/riskio/idempotency-module/config/riskio_idempotency.global.php.dist`
- destination: `config/autoload/riskio_idempotency.global.php`

### Zend Framework

[](#zend-framework)

In Zend Framework application, you must enable the module by adding `Riskio\IdempotencyModule` in your `application.config.php` file.

### Zend Expressive

[](#zend-expressive)

In Zend Expressive application, you must add the `Riskio\IdempotencyModule\IdempotencyMiddleware` middleware in `config/pipeline.php` file at the very first pipeline records.

```
