Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "serviced", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Microservice dependency readiness probe", | ||
@@ -5,0 +5,0 @@ "main": "serviced.js", |
@@ -12,3 +12,6 @@ # Serviced | ||
## Motivation | ||
When working with microservices (particularly with Kubernetes), we often find we need to be prepared for variable times in backing service availability. Most times these are available and ready before we even probe them but some times they are not like in the case of a service needing to apply some configuration specific to a consuming service, etc. Serviced provides a way to probe multiple services with varying probe and retry configurations wrapped in a promise so you can, for example, not start an API server until all its backing services are available and ready. | ||
## Usage | ||
@@ -20,16 +23,20 @@ | ||
### Test that a single service returns status code 200. | ||
```javascript | ||
const Serviced = require('serviced'); | ||
// Test that a single service returns status code 200. | ||
new Serviced('http://exmample.com').then(() => { | ||
// Your service is online and returns status code 200. | ||
}); | ||
``` | ||
// Test that multiple services returns status code 200. | ||
### Test that multiple services return status code 200. | ||
```javascript | ||
new Serviced('http://svc-a.com', 'http://svc-b.com').then(() => { | ||
// Both services are online and return status codes 200. | ||
}); | ||
``` | ||
// Test the response body from a service request with a test function. | ||
### Test the response body from a service request with a test function. | ||
```javascript | ||
new Serviced({ | ||
@@ -43,4 +50,6 @@ url: 'http://svc-a.com', | ||
}); | ||
``` | ||
// Test the response body from multiple service requests with test functions. | ||
### Test the response body from multiple service requests with test functions. | ||
```javascript | ||
new Serviced({ | ||
@@ -59,4 +68,21 @@ url: 'http://svc-a.com', | ||
}); | ||
``` | ||
// Pass additional options to underlying request and retry modules. | ||
### Different options for multiple services. | ||
```javascript | ||
// http://svc-a.com is only tested for a 200 response. | ||
// http://svc-b.com's response body is passed to your own test function. | ||
new Serviced('http://svc-a.com', { | ||
url: 'http://svc-b.com', | ||
test(body) { | ||
return body.bar === true; | ||
}, | ||
}).then(() => { | ||
// Services are online and responses pass supplied tests. | ||
}); | ||
``` | ||
### Pass additional options to underlying request and retry modules. | ||
The optional `.request` and `.retry` objects are passed through to the request and retry module instances respectively so you can control those as you deem necessary. It's a straight passthrough so please read their docs to find out what options are available for each. | ||
```javascript | ||
new Serviced({ | ||
@@ -63,0 +89,0 @@ url: 'http://svc-a.com', |
10238
107