@node-idempotency/fastify
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

@node-idempotency/fastify

A Fastify plugin that makes requests idempotent Implements @node-idempotency/core as fastify plugin.


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 plugin to fastify)
  • Customizable: options to tweak the library as per your need.
  • RFC compliant: Adheres to standards for compatibility with other systems/clients.

How?

No Image

instal
npm i @node-idempotency/fastify
usage
import fastify from "fastify";
import fp from "fastify-plugin";
import {
  idempotencyAsPlugin,
  type IdempotencyPluginOptions,
  StorageAdapterEnum,
} from "@node-idempotency/fastify";

const server = fastify();
server.register(fp<IdempotencyPluginOptions>(idempotencyAsPlugin), {
  storage:{
    adapter: StorageAdapterEnum.memory
    options: ...adapterOptions
  },
  //...IdempotencyOptions
});

//...your rest of logic
export default server;
  • storage.adapter can either be memory, redis or an instance of Storage interface.
  • storage.options are options to the storage client, required for redis, is client options of redis client.
  • idempotencyOptions are the IdempotencyOptions passed to @node-idempotency/core/Idempotency

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.5100latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.5100
1.0.412
1.0.31
1.0.21
1.0.11
1.0.01

Package Sidebar

Install

npm i @node-idempotency/fastify

Weekly Downloads

82

Version

1.0.5

License

MIT

Unpacked Size

38.7 kB

Total Files

39

Last publish

Collaborators

  • maehendra9