This module contain Common HTTP service call functionality (retry, correlation headers, etc.), used by backed services.
npm install
const { HttpClient } = require('healthpass-http-lib');
let httpClient = new HttpClient({
url: 'https://my-unprotected-api.cloud/resources/123',
})
httpClient.invoke()
.then(response => {})
.catch(err => {})
const { HttpClient } = require('healthpass-http-lib');
let token, logger, correlationId;
// ...get or generate values for the above variables
let httpClient = new HttpClient({
method: 'post'
url: 'https://my-protected-api.cloud/resources/123',
bearerToken: token, // will be set in the Authorization header with "Bearer " as the prefix
logger: {
instance: logger,
functionName: 'trace' // the request and response will be logged using `logger.trace(...)`
},
retry: {
count: 5
delay: function(retryAttempt) {
return 2000 * retryAttempt;
}
},
body: {
foo:'bar', // this will be posted as JSON, by default
},
timeout: 15000,
correlationId: corelationId // this will propagated as the request header x-correlation-id for global tracing
})
httpClient.invoke()
.then(response => {})
.catch(err => {})
- [axios] (https://www.npmjs.com/package/axios) is used to underpin the http functionality
- The module exports a class
HttpClient
, and middleware for setting standard request or response headers
This section lists license details of libraries / dependencies.