flashheart
Advanced tools
Comparing version 2.6.1 to 2.7.0
@@ -27,2 +27,3 @@ var _ = require('lodash'); | ||
const GET = 'get'; | ||
const HEAD = 'head'; | ||
const PUT = 'put'; | ||
@@ -234,2 +235,13 @@ const DELETE = 'del'; | ||
Client.prototype.head = function (url, opts, cb) { | ||
if (typeof opts === 'function') { | ||
cb = opts; | ||
opts = {}; | ||
} | ||
this._requestWithCircuitBreaker(HEAD, url, opts, function (err, body, res) { | ||
cb(err, body, res); | ||
}); | ||
}; | ||
Client.prototype.post = function (url, requestBody, opts, cb) { | ||
@@ -236,0 +248,0 @@ if (typeof opts === 'function') { |
{ | ||
"name": "flashheart", | ||
"version": "2.6.1", | ||
"version": "2.7.0", | ||
"description": "A fully-featured REST client built for ease-of-use and resilience", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -283,2 +283,10 @@ # flashheart | ||
### `client.head` | ||
#### Parameters | ||
* `url` - The URL to be requested | ||
* `opts` - _optional_ - A set of options. All of the [request options](https://github.com/request/request#requestoptions-callback) are supported | ||
* `callback` - A function called with the [callback return values](https://github.com/bbc/flashheart#callback-return-values) | ||
### `client.put` | ||
@@ -319,9 +327,2 @@ | ||
## Contributing | ||
* If you're unsure if a feature would make a good addition, you can always [create an issue](https://github.com/bbc/flashheart/issues/new) first. | ||
* We aim for 100% test coverage. Please write tests for any new functionality or changes. | ||
* Make sure your code meets our linting standards. Run `npm run lint` to check your code. | ||
* Maintain the existing coding style. There are some settings in `.jsbeautifyrc` to help. | ||
## Why Flashheart? | ||
@@ -328,0 +329,0 @@ |
@@ -890,2 +890,61 @@ var _ = require('lodash'); | ||
}); | ||
describe('.head', function () { | ||
it('makes a head request', function (done) { | ||
api.head(path).reply(200); | ||
client.head(url, function (err, body, resp) { | ||
assert.ifError(err); | ||
assert.strictEqual(resp.statusCode, 200); | ||
assert.strictEqual(body, undefined); | ||
done(); | ||
}); | ||
}); | ||
it('returns an error when the API returns a 5XX status code', function (done) { | ||
api.head(path).reply(500); | ||
client.head(url, function (err) { | ||
assert.ok(err); | ||
done(); | ||
}); | ||
}); | ||
it('retries failed requests', function (done) { | ||
client = Client.createClient({ | ||
retries: 2, | ||
retryTimeout: 0 | ||
}); | ||
nockRetries(2, { | ||
httpMethod: 'head', | ||
successCode: 200 | ||
}); | ||
client.head(url, done); | ||
}); | ||
it('trips the circuit breaker when multiple requests fail', function (done) { | ||
client = Client.createClient({ | ||
retries: 0, | ||
circuitBreakerMaxFailures: 3 | ||
}); | ||
nock.cleanAll(); | ||
api.head(path).times(6).reply(500); | ||
async.times(5, function (i, cb) { | ||
client.head(url, {}, function () { | ||
// send an empty callback to avoid the error | ||
// from stopping the `times` | ||
cb(); | ||
}); | ||
}, function () { | ||
client.head(url, {}, function (err) { | ||
assert(err); | ||
assert.include(err.message, 'Circuit breaker is open'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
274493
14
1607
331