0.2.1 • Published 11 months ago

vindu v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Vindu

Rate limiter for APIs.

Made for the Waveorb Web Application Development Framework.

Install

npm i vindu

Usage

var vindu = require('vindu')

var $ = { req, res, db }

var options = {
  // The key used to identify the API user, default is the request IP
  key: $.req.ip,

  // The name of the database collection to use
  collection: 'request'
}

// Returns the number of requests per minute, month and year
var [minute, month, year] = await vindu($, options)

function rateLimit(res) {
  res.statusCode = 429
  res.end('')
}

var apikey = $.req.params.apikey
var account = await $.db('account').get({ apikey })

if (minute > account.limit) {
  return rateLimit($.res)
}

MIT Licensed. Enjoy!

Created by Eldøy Projects

0.2.1

11 months ago

0.2.0

11 months ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago