ajax-limited

1.1.3 • Public • Published

ajax-limited

Build Status Coverage Status


A rate-limited version of $.ajax with support for slow start on wakeup.

Installing

npm install --save ajax-limited

Usage

var $ = require('jquery');
var ajaxLimited = require('ajax-limited');

ajaxLimited.configure($, {
  bucketSize: 9,
  tokensPerInterval: 9,
  interval: 3000,
});

ajaxLimited.get({
  bucketSize: 2,
  tokensPerInterval: 2,
  interval: 3000,
});

Documentation

AjaxLimited

Manages the set of TokenBuckets limitting AJAX requests.

Params:

  • Object [options] Optional root TokenBucket options

.prototype.configure(target, [options])

Configures rate limitting into an object.

Params:

  • Object target
  • Object [options]

.prototype.restore([target])

Restores the original ajax method on the configured targets or a target object.

Params:

  • Object [target]

Return:

  • Function originalAjax

.prototype.slowStart(options)

Receives initial options for each HTTP method (or all of them), modifies buckets so they start with them and slowly transitions rate limitting until the original rates are reached.

Params:

  • Object options

Example

ajaxLimited.slowStart({
  get: { // Slows down get to this rate
    bucketSize: 9,
    tokensPerInterval: 9
  },
  'put,patch,post,delete': { // Slows down post, put, patch, delete to this rate
    bucketSize: 9,
    tokensPerInterval: 0,
  },
  transitionTime: 9000, // Takes 9s to reach normal speed
  interval: 3000        // Updates speed every 3s
});

Readme

Keywords

none

Package Sidebar

Install

npm i ajax-limited

Weekly Downloads

4

Version

1.1.3

License

See LICENSE

Last publish

Collaborators

  • toggl