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

@mvp-rockets/namma-external-wrapper

v1.0.0

Published

A javascript-based wrapper for making API calls with the ability to add retries and ratelimits.

Downloads

1,616

Readme

1. Introduction

A javascript-based wrapper for making API calls with the ability to add retries and ratelimits.

2. Installation

npm i @mvp-rockets/namma-external-wrapper

3. How to use

// A simple REST "Get" example with retries 2 and minTimeout 5000.

    const ExternalWrapper = require('@mvp-rockets/namma-external-wrapper');

    const externalWrapper = new ExternalWrapper({ retries: 2, minTimeout: 5000 });
	const resultFromWrapper = await externalWrapper.perform({
		url: 'http://localhost:3000/test'
	});

    console.log(resultFromWrapper) // Result.Ok("Your result")
    or
    console.log(resultFromWrapper) // Result.Error("Error in case of failure")
// A simple REST "Post" example with retries 2 and minTimeout 5000.

    const ExternalWrapper = require('@mvp-rockets/namma-external-wrapper');

    const { name } = req.body;
	const externalWrapper = new ExternalWrapper({ retries: 2, minTimeout: 5000 });
	const resultFromWrapper = await externalWrapper.perform({
		url: 'http://localhost:3000/test',
		method: 'post',
		data: {
			name
		}
	});
    console.log(resultFromWrapper) // Result.Ok("Your result")
    or
    console.log(resultFromWrapper) // Result.Error("Error in case of failure")
// A simple REST "Get" example with retries 2, minTimeout 5000 and rateLimit 1 request per perMilliseconds.
    const ExternalWrapper = require('@mvp-rockets/namma-external-wrapper');
    const externalWrapper = new ExternalWrapper(
		{ retries: 2, minTimeout: 5000 },
		{
			maxRequests: 1,
			perMilliseconds: 10000,
			maxRPS: 1
		}
	);
	const resultFromWrapper = await externalWrapper.perform({
		url: 'http://localhost:3000/test'
	});
// Get raw response from the API call.

// Pass the second arg as true to the perform method to get actual response from the API call. 
// This response won't be of the type folktale Result.
// This is an optional arg and is false by default.

app.get('/raw', async (req, res) => {
	try {
		const externalWrapper = new ExternalWrapper({ retries: 2, minTimeout: 5000 });
		const resultFromWrapper = await externalWrapper.perform({ url: 'http://localhost:3000/test' }, true);
		res.send(resultFromWrapper);
	} catch (error) {
		res.send(error);
	}
});

4. Imp Notes

  1. Internally the lib use axios to make rest call. You can use any REST methods call by passing accepted data for details: https://www.npmjs.com/package/axios

  2. ExternalWrapper take two object when you are initializing object. new ExternalWrapper(retryObject,rateLimitObject)

    1. retryObject details : https://www.npmjs.com/package/async-retry
      1. retries: The maximum amount of times to retry the operation. Default is 5.
      2. factor: The exponential factor to use. Default is 2.
      3. minTimeout: The number of milliseconds before starting the first retry. Default is 1000.
      4. maxTimeout: The maximum number of milliseconds between two retries. Default is Infinity.
    2. rateLimitObject details: https://www.npmjs.com/package/axios-rate-limit
      1. maxRequests: The no of request : example 2
      2. perMilliseconds: no of request perMilliseconds example 1
      3. maxRPS: maxRPS is a shorthand for perMilliseconds: 1000, and it takes precedence.if specified both with maxRequests and perMilliseconds