ratelimiter: In-memory rate limiter

[ bsd3, library, web ] [ Propose Tags ] [ Report a vulnerability ]

An in-memory rate limiter implementation


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0
Dependencies base (>=4.7 && <5), containers, extra, mtl, time, timespan, vector [details]
License BSD-3-Clause
Copyright 2020 Alexander Thiemann <mail@thiemann.at>
Author Alexander Thiemann <mail@thiemann.at>
Maintainer Alexander Thiemann <mail@thiemann.at>
Category Web
Home page https://github.com/agrafix/ratelimiter#readme
Bug tracker https://github.com/agrafix/ratelimiter/issues
Source repo head: git clone https://github.com/agrafix/ratelimiter
Uploaded by AlexanderThiemann at 2020-12-21T04:45:52Z
Distributions NixOS:0.1.0
Downloads 252 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-12-21 [all 1 reports]

Readme for ratelimiter-0.1.0

[back to package description]

Haskell: ratelimiter

A simple in-memory rate-limiter library.

Usage

import Control.RateLimiter
import qualified Data.Vector as V

main :: IO
main =
  -- one rate limiter can have multiple rules
  do limiter <- 
        newRateLimiter $ V.fromList
        [ RateLimitConfig (RollingWindow 60) 200 -- 200 per minute
        , RateLimitConfig (RollingWindow 3600) 400 -- 400 per hour
        ]
     let myRateLimitedFunction =
           do isLimited <- isRateLimited () limiter
              if isLimitd then pure Nothing else Just <$> someExpensiveWork
     -- ... use myRateLimitedFunction