https://github.com/ChrisWoollon/http-queue/
https://www.npmjs.com/package/http-queue
http-queue
Queue HTTPS requests to, for example, limit the number of API requests made in X amount of time.
I found myself copy+pasting this code into lots of projects, so decided I'd just make it available.
Usage
npm install http-queue
let httpQueue = ;const x = 1000; // ms between requestshttpQueue = x; // Runs on inithttpQueue;// Runs 1000ms laterhttpQueue;
Alternatively, newRequest
takes an object as its first parameter;
var options = url: https://jsonplaceholder.typicode.com/posts/1queue;
You can also pass functions as variables for multi-use, and handle errors in their own function
let { console;}let { console; // Do something with the error...}httpQueue;
Parameters:
Parameter | Example |
---|---|
url | 'http://example.com/' |
method | 'GET' |
headers | { Content-Type': 'application/json' } |
body | JSON data |
Content-Type supported: |
---|
application/json |
application/x-www-form-urlencoded |
You can also define the URL in its constituent parts, e.g.
Parameter | Example |
---|---|
options.protocol | 'http' |
options.hostname | 'example.com' |
options.host | 'example.com:8888' |
options.path | '/get/the/path/' |
options.port | 8888 |
Contribute
Have a feature request, spotted an issue? Get in touch or make a pull request: https://github.com/ChrisWoollon/http-queue