0.2.1 • Published 7 years ago

http-queue v0.2.1

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

https://github.com/ChrisWoollon/http-queue/

https://www.npmjs.com/package/http-queue

http://chriswoollon.co.uk/

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 = require('http-queue');
const x = 1000; // ms between requests
httpQueue = new httpQueue(x);

// Runs on init
httpQueue.newRequest('https://google.co.uk', function(data) {
	console.log(data);
});
// Runs 1000ms later
httpQueue.newRequest('https://github.com', function(data) {
	console.log(data);
});

Alternatively, newRequest takes an object as its first parameter;

var options = {
	url: https://jsonplaceholder.typicode.com/posts/1
}
queue.newRequest(options, function(data) {
	console.log(data);
});

You can also pass functions as variables for multi-use, and handle errors in their own function

let onResponse = function(data) {
	console.log(data);
}
let error = function(err) {
	console.log(err);
	// Do something with the error...
}
httpQueue.newRequest('https://twitter.com', onResponse, error);

Parameters:

ParameterExample
url'http://example.com/'
method'GET'
headers{ Content-Type': 'application/json' }
bodyJSON data
Content-Type supported:
application/json
application/x-www-form-urlencoded

You can also define the URL in its constituent parts, e.g.

ParameterExample
options.protocol'http'
options.hostname'example.com'
options.host'example.com:8888'
options.path'/get/the/path/'
options.port8888

Contribute

Have a feature request, spotted an issue? Get in touch or make a pull request: https://github.com/ChrisWoollon/http-queue

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago