Package Exports
- @node-idempotency/express
- @node-idempotency/express/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@node-idempotency/express) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@node-idempotency/express
An Express middleware that makes requests idempotent
Implements @node-idempotency/core
as express middleware.
Why?
Network requests are unpredictable; clients/proxies may send duplicate or concurrent requests due to retries or network issues. To ensure smooth operation, servers must process each request only once. This package detects and handles duplicates, preventing issues like double charging the customer. It's:
- Race Condition free: Ensures consistent behavior even during concurrent requests.
- Modular: Easily integrates with your storage or existing implementation.(as simple as registering a middleware)
- Customizable: options to tweak the library as per your need.
- RFC compliant: Adheres to standards for compatibility with other systems/clients.
How?
instal
npm i @node-idempotency/express
usage
import * as express from "express";
//server.ts
export default async (): Promise<express.Application> => {
const app = express();
const middleware = await idempotencyAsMiddleware({
storage:{
adapter: StorageAdapterEnum.memory
options: ...adapterOptions
},
...idempotencyOptions
});
app.use(middleware);
//register routes here
app.use(errorHandler); //your custom error handler
return app;
};
storage.adapter
can either bememory
,redis
or an instance ofStorage
interface.storage.options
are options to the storage client, required forredis
, is client options of redis client.idempotencyOptions
are theIdempotencyOptions
passed to@node-idempotency/core/Idempotency