WordPress plugin intelligence profile

WP REST API Idempotent Requests

Allow REST API clients to safely retry requests in case of network errors without risk of the request being processed twice.

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 4.8
Current version1.0
WordPress coverageTested up to WordPress 4.8
Minimum stackWP 4.7 · PHP —
Directory statusactive
Last directory update9 Apr 20179y ago
Active installationsNewAdoption metric — not a quality score
WordPress.org ratingNo WordPress.org ratings yet
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records WP REST API Idempotent Requests version 1.0 as active, updated 9y ago and tested up to WordPress 4.8.

Overview

About this plugin

When a network error is encountered, API clients should be able to retry a request without a risk of their request being processed twice.

WP API Idempotence adds support for clients to include an idempotency key that uniquely identifies that request. If the server detects

that a request with the same key has already been processed or is currently being processed, the response for the initial request will

be returned.

For Example:

", "status": "draft", "idempotency_key": "1ced64e9-9537-4b7b-9919-444d9e15e201" }

Configuration

  • Idempotency key can either be passed in the request header or the request body.
  • The idempotency key name can be customized.
  • Change the HTTP methods the idempotency key is supported for. Defaults to POST, PUT, PATCH.

A sample request interface is included to demonstrate the selected configuration.

Developers

The plugin includes two actions to modify the dependency injection container (DIC) and insert custom services.

The wp_api_idempotence_initialize_container_builder action allows you to modify the Dependency Injection builder itself and

the wp_api_idempotence_initialize_container action allows you to override dependencies. For example:

add_action( 'wp_api_idempotence_initialize_container', function( $container ) { $container->set( '_dataStore', DI\object( 'YourName\CustomDataStore' ) ); } );

Under the hood, the plugin is made up of a DataStore, RequestHasher, ResponseSerializer and RequestPoller.

The DataStore is primarily responsible for retrieving or storing an idempotent request. By default, requests

are stored in a custom database table. This could be substituted for a custom driver by implementing the DataStore

interface. For example a Redis server.

The RequestHasher produces a unique hash for a WP_REST_Request object. This hash is based off of the contents of

the request, not for the object via spl_object_hash or similar. This can also be substituted by implementing the

RequestHasher interface.

The ResponseSerializer converts a WP_REST_Response or WP_Error object back and forth from a string representation.

The default JSON serializer supports filtering the serialization process using the wp_api_idempotence_serialized_response_data

and wp_api_idempotence_attach_serialized_response_data filters. php.

The entire serializer can be substituted by implementing the ResponseSerializer interface.

Finally, the RequestPoller class polls the data store for a response if it is determined that an idempotent request

is currently being processed when another request with the same key arrives. By default, the data store is polled

every seconds a maximum of 15 times to try and retrieve a response object. If no response is found, an error with code

rest_duplicate_idempotency_key will be returned. sleepSeconds and

maxQueries in the DIC. The RequestPoller can also be entirely subsituted by implementing the RequestPoller

interface.

Contributing

This plugin is hosted on GitHub. Issues and pull requests are welcomed.

WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • rest api
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 4.8

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 4.8.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to4.8
Minimum requirementsWordPress 4.7 · PHP not listed
Update activity9 Apr 20179y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.