Service Request Client
Utility module for making HTTP requests against discoverable HTTP services.
Supported service discovery technologies include:
- Container DNS
- ZooKeeper (to be added in the future)
- Consul (to be added in the future)
- Basic Host Port
Basic Usage
The following is the most basic example of a Container DNS client:
'use strict'; const Client = ContainerDNSClient; // Instantiate a clientconst client = 'service-name' 8001 'my/service/path/v1' verbose: true retries: 2 timeoutMs: 3000 correlationHeaderName: 'X-Unity-CorrelationID' ; const query = "myParam": "myValue" ; const headers = "Content-Type": "application/json" ; const body = "prop1": "value1" "prop2": "value2" ; // Invoke a GET request against the service endpoint (promise style)client ; // Invoke a GET request against the service endpoint (async/await style)let res; try res = await client; console; catch err console; // Invoke a PUT request against the serviceclient ; // Invoke a POST request against the serviceclient ; // Invoke a DELETE request against the serviceclient ; // Invoke a GET request against the service clientmethod'GET' 'item/search' query headers body ;
The following is the most basic example of a Host Port client:
'use strict'; const Client = HostPortClient; // Instantiate a clientconst client = 'api.test.io' 80 'v1' verbose: true retries: 2 timeoutMs: 3000 ; const query = "myParam": "myValue" ; const headers = "Content-Type": "application/json" ; const body = "prop1": "value1" "prop2": "value2" ; // Invoke a GET request against the service endpoint (promise style)client ; // Invoke a GET request against the service endpoint (async/await style)let res; try res = await client; console; catch err console; // Invoke a PUT request against the serviceclient ; // Invoke a POST request against the serviceclient ; // Invoke a DELETE request against the serviceclient ; // Invoke a GET request against the service clientmethod'GET' 'item/search' query headers body ;