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 🙏

© 2025 – Pkg Stats / Ryan Hefner

request-container

v0.0.5

Published

a request container enables you to manage http request

Downloads

2

Readme

request-container

This library is an extremely lightweight only do two things:

  1. Same http requests should derive same result at the same range of time.

  2. Every http requests should pass to a container so that developer could manage it anytime anywhere.

Senarios

  1. For any component oriented application such as react, vue, angular, each component works independently and isolately. Therefore, if any two component dispatch same http request at around same time, mutiple same requests made. TO mitigate this, request-conatinersolves this problem to ensure all same requests are only made one and only one outgoing http request at same range of time.

  2. For Single Page Applications, they make use of Html5 History Api to manage routing. However, any requests that made in previous page might be hard to manage/cancel. Imagine the performance when a user is uploading 100mb file and unpatiently leave the page, the 100mb file upload connection is still there if developer not manually terminate it. request-conatiner solves this problem to as it provide a container to preserve processing request.

Environment

NodeJS

Browser

Language

JavaScript

Typescript

How to use

What you need to do is to pass your promise request in the requestContainer and it will return you a promiseState which contains your promise as well as current promise request status (none/loading/success/error).

Javascript
    import RequestContainer from 'request-container';
    const requestContainer = RequestContainer.getInstance();

    // const promiseState = requestContainer.put(<a key used to identify your request>, 
    // <a function that will execute a request and return a promise>);
    const promiseState = requestContainer.put(JSON.stringify(requestParam), promiseFn);
Typescript
    import RequestContainer from 'request-container';
    const requestContainer = RequestContainer.getInstance();

    //type RequestParamType = {url: 'www.example.com/api', data: {token:123}, method: 'get'};
    //promiseFn:() =>Promise<any>, e.g.  promiseFn = ()=>$.ajax(...);
    const promiseState = requestContainer.put(JSON.stringify(requestParam), promiseFn);

Concurrent Same Request

Here is a scenario for concurrent same request (for more example please check the tests folder)

    import RequestContainer from 'request-container';
    
    function httpRequest(duration:number): Promise<void>{
       return new Promise(()=>setTimeout(resolve,number))
    }
    
    const requestContainer = RequestContainer.getInstance();
    
    //assume first attempt request consumes 2 sec
    const requestParam1 = {url: 'www.example.com/api', data: {token:123}, method: 'get'};
    const promiseFn1 = ()=>httpRequest(2000);
    const promiseState1 = requestContainer.put(JSON.stringify(requestParam1), promiseFn1);
    
    //assume second attempt request consumes 4 sec, it doesn't matter how long it takes
    const requestParam2 = {url: 'www.example.com/api', data: {token:123}, method: 'get'};
    const promiseFn2 = ()=>httpRequest(4000);
    const promiseState2 = requestContainer.put(JSON.stringify(requestParam2), promiseFn2);
    
    /**
    * since they are exactly the same request, therefore if request1 sent
    * request2 will be intercepted and points to request1, which means request1 will share the response with request2
    * the entire process therefore will have one and only one outgoing request.
    */

Roadmap

The request-container will be used as a small part of module in next library which is about smart http request caching. I am stuck at how to create a suitable algorithm to handle cache garbage collection (GC). Once done, it will make more sense of why request-container is simple but very useful for any request module for any project.

Unit Testing

This library has been gone through proper unit testing under the tests folder, feel free to use the request-container :)

License

MIT