
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
request-container
Advanced tools
This library is an extremely lightweight only do two things:
Same http requests should derive same result at the same range of time.
Every http requests should pass to a container so that developer could manage it anytime anywhere.
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.
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.
NodeJS
Browser
JavaScript
Typescript
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).
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);
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);
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.
*/
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.
This library has been gone through proper unit testing under the tests folder, feel free to use the request-container :)
MIT
FAQs
a request container enables you to manage http request
We found that request-container demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.