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

threaded-requester

v1.0.1

Published

A simple tool to simulate HTTP requests. Recommended as a fast way to deal with token auth and other requests that need to be executed every certain ammount of time.

Downloads

2

Readme

Threaded Requester

A simple tool to simulate parallelized HTTP requests. Recomended as a fast way to deal with token authentication/authorization, and other requests that need to be executed every certain amount of time.

Requirements

Your environment must support ES6 Module Syntax.

Installation

On your project folder run

npm install threaded-requester --save

or

yarn add threaded-resquester

depending on the package manager your are using on your project.

Usage

You need to import the Requester class from the threaded-requester package. Then, for every request you want to execute programatically you need to create a different instance of the Requester class.

The Requester class constructor receives two parameters. The first one is mandatory and is the url to make the request to. The second one is optional and is an object with the options to configure your request. Available options and their default values are listed below.

Example

This is an example where we want to make two kind of requests. One is a GET request that is executed every minute and the other one is a POST that is executed every two minutes.

import Requester from "threaded-requester";

let priceRequester = new Requester("https://www.myapi.com/1/price", {
  timeout: 60000, // time in miliseconds
  callback: console.log,
});

let postInfo = new Requester("https://www.myapi.com/personalInfo", {
  timeout: 120000,
  method: "POST",
  headers: {
    "content-type": "application/json",
  },
  body: JSON.stringify({
    firstName: "John",
    lastName: "Doe",
    age: 24,
  }),
  callback: () => console.log("Info Posted!"),
});

// Run the "threads" to make the request every time [] they are needed
priceRequester.run();
postInfo.run();

The callback option is a function to be executed once the request is done. The response of the request is passed as an argument to this function. So, the priceRequest will print to the console the response received and the postInfo requester will print to the console the message Info Posted! every time it made a request.

To stop the requester's execution you have to call its stop method

priceRequester.stop();
postInfo.stop();

Note that after stopping the execution is highly likely that one request was waiting for its next execution, in that case the request will be executed one more time and then it will not be executed anymore until you call the run method again.

Options

Here's the list of all available options to pass to a requester instance.

| Option | Default | Description | | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | method | 'GET' | The request's HTTP method. | | headers | none | The request's HTTP header. | | body | none | The body of the request. | | timeout | 60000 | The request is made every timeout miliseconds. | | callback | none | A function to be called once the request is finished. The response of the request is passed as a parameter to this function. | | failure | none | A function to be called when the request fails. The response of the request is passed as a parameter to this function. The request will still be executed no matter whether it has failed. |