cork
An API utility belt for request.
![Build Status](https://secure.travis-ci.org/thisandagain/cork.png)
Cork is a minimal layer that sits on top of the request module and adds a few patterns that make working with 3rd party APIs simpler.
Installation
npm install cork
Basic Use
var cork = require('cork');
cork.register('buzz', {
'method': 'get',
'headers': {
'x-api-key': 'someApiKeyGoesHere'
},
'json': {}
'timeout': 20000
});
cork.request('buzz', {
'uri': 'https://api.geek.com/some/resource'
}, function (err, body) {
console.dir(body);
});
cork.request('buzz', {
'method': 'post'
'uri': 'https://api.geek.com/some/other/resource',
'json': {
'foo': 'bar'
}
}, function (err, body) {
console.dir(body);
});
Base URIs
A base URI can be defined during registration by passing the optional base
parameter:
cork.register('dork', {
base: 'http://api.nerd.com',
});
cork.request('dork', {
uri: '/yet/another/resource'
}, function (err, body) {
});
API Limits / Throttling
When registering a service, Cork accepts an optional throttle
parameter which represents a request limit expressed in milliseconds. Any requests that subsequently hit the throttle limit will be queued and processed in FIFO order. For example, let's say that we are working with an API that only accepts 10 requests per second:
cork.register('geek', {
throttle: 100
});
Testing
npm test