npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rate-limiter-api

v1.0.11

Published

A simple library to easily manage rate limits of APIs without any hassles.

Downloads

31

Readme

Rate Limiter API

A simple library to easily manage rate limits of APIs without any hassles.

Rate Limiter API image

All Contributors MIT License npm version Join the chat at https://gitter.im/abhisekp/rate-limiter-api

Table of Contents

Usage

Browser

<script src="https://cdn.rawgit.com/abhisekp/rate-limiter-api/master/dist/rate-limiter-api.js"></script>

<script type="text/javascript">
  var rateLimiter = RateLimiterAPI()
</script>

NodeJS

$ {sudo -H} npm install -S rate-limiter-api
import RateLimiterAPI from 'rate-limiter-api'

Public Interface

  • rateLimiter = RateLimiterAPI({threshold: 5})
  • rateLimiter.limit(requestHandler) => Promise
    • rateLimiter.updateRateLimits on success to update rates
    • requestHandler(responseHandler) on success to continue

import RateLimiterAPI from 'rate-limiter-api'

const rateLimiter = RateLimiterAPI({
  threshold: 5, // leave `threshold` amount of api requests intact (minimum: 1)
})

Pass an optional threshold value which would limit the total rate limits till the threshold is reached in the current session pulse till rate reset.


const request = rateLimiter.limit(requestHandler) //=> Promise

function requestHandler(responseHandler) {
  fetch('https://api.example.com/get')
    .then((response) => {
      rateLimiter.updateRateLimits({
        rateLimit: response.headers.rateLimit,
        rateRemaining: response.headers.rateRemaining,
        rateReset: response.headers.rateReset,
      })

      responseHandler(null, response.body)
    })
    .catch((err) => {
      responseHandler(err)
    })
}

The limit method is passed a requestHandler which would manage the request and then call the node-style responseHandler callback (which gets passed by the RateLimiter library to the requestHandler function) after the request is successful or unsuccessful accordingly.

The request method returns a Promise.

responseHandler(Error, response)
where the first parameter is the Error object and the seconds parameter is the response.

responseHandler callback must be called to continue getting responses.

Update the rate limits i.e. {rateLimit, rateRemaining, rateReset} got from the header using updateRateLimits method.


request
  .then((response) => {
    console.dir(response, {colors:1})
  })
  .catch((error) => {
    console.error(error.message)
  })

When the request completes, the Promise resolves and can be thenable to get the response or error.

Stats

1 text file.
1 unique file.
0 files ignored.

https://github.com/AlDanial/cloc v 1.66 T=0.04 s (22.7 files/s, 2516.9 lines/s)

Language|files|blank|comment|code :---|:---:|:---:|:---:|:---: JavaScript|1|12|37|62

Technologies Used

  • Babel — Transpiles modern JS to compatible and runnable JS
  • Stamp It - Composable inheritance object creation libray
  • Async JS - Utility for asynchronous functions
  • Lodash - Utility library

Help & Support

Contributors

| Abhisek Pattnaik💻 🎨 📖 💡 | | :---: |

This project follows the all-contributors specification.

All types of Contributions are Welcome :pray:

License

MIT © Abhisek Patnaik