net4j-throttle-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.13 • Public • Published

net4j-throttle-plugin

Throttle each request in waiting time.

Only same method, url, params and data will be throttled.

import Net from 'net4j';
import NetThrottle, { ThrottleConfig } from 'net4j-throttle-plugin';

// Merge plugin config to net4j config,then you can use it in every requst in net4j
declare module 'net4j' {
  interface Config extends ThrottleConfig {}
}

const net = new Net({
  plugins: [
    new NetThrottle({
      wait: 2000, // default is 1000 ms
    }),
  ]
});

// api/goods with id=1 can only request once in 2 seconds
await net.get('api/goods', {params: {id: 1}});

// api/goods with id=2 can only request once in 2 seconds
await net.get('api/goods', {params: {id: 2}});

Readme

Keywords

Package Sidebar

Install

npm i net4j-throttle-plugin

Weekly Downloads

1

Version

1.0.13

License

MIT

Unpacked Size

10.6 kB

Total Files

5

Last publish

Collaborators

  • forthedamn