HTTP client provider for @mdf.js based on axios.
Using npm:
npm install @mdf.js/http-client-provider
Using yarn:
yarn add @mdf.js/http-client-provider
Check information about @mdf.js providers in the documentation of the core module @mdf.js/core.
The provider implemented in this module wraps the axios client.
import { HTTP } from '@mdf.js/http-client-provider';
const client = HTTP.Factory.create({
name: `myHTTPClientProvider`,
config: {
requestConfig?: {...}, // a CreateAxiosDefaults object from axios
httpAgentOptions: {...}, // an http AgentOptions object from Node.js
httpsAgentOptions: {...}, // an https AgentOptions object from Node.js
},
logger: myLoggerInstance,
useEnvironment: true,
});
Defaults:
{}
Environment: remember to set the useEnvironment
flag to true
to use these environment variables.
{
requestConfig: {
baseURL: process.env['CONFIG_HTTP_CLIENT_BASE_URL'],
timeout: process.env['CONFIG_HTTP_CLIENT_TIMEOUT'],
auth: { // Only if username and password are set
username: process.env['CONFIG_HTTP_CLIENT_AUTH_USERNAME'],
password: process.env['CONFIG_HTTP_CLIENT_AUTH_PASSWORD'],
},
},
httpAgentOptions: {
keepAlive: process.env['CONFIG_HTTP_CLIENT_KEEPALIVE'],
keepAliveInitialDelay: process.env['CONFIG_HTTP_CLIENT_KEEPALIVE_INITIAL_DELAY'],
keepAliveMsecs: process.env['CONFIG_HTTP_CLIENT_KEEPALIVE_MSECS'],
maxSockets: process.env['CONFIG_HTTP_CLIENT_MAX_SOCKETS'],
maxTotalSockets: process.env['CONFIG_HTTP_CLIENT_MAX_SOCKETS_TOTAL'],
maxFreeSockets: process.env['CONFIG_HTTP_CLIENT_MAX_SOCKETS_FREE'],
},
httpsAgentOptions: {
keepAlive: process.env['CONFIG_HTTP_CLIENT_KEEPALIVE'],
keepAliveInitialDelay: process.env['CONFIG_HTTP_CLIENT_KEEPALIVE_INITIAL_DELAY'],
keepAliveMsecs: process.env['CONFIG_HTTP_CLIENT_KEEPALIVE_MSECS'],
maxSockets: process.env['CONFIG_HTTP_CLIENT_MAX_SOCKETS'],
maxTotalSockets: process.env['CONFIG_HTTP_CLIENT_MAX_SOCKETS_TOTAL'],
maxFreeSockets: process.env['CONFIG_HTTP_CLIENT_MAX_SOCKETS_FREE'],
rejectUnauthorized: process.env['CONFIG_HTTP_CLIENT_REJECT_UNAUTHORIZED'],
ca: process.env['CONFIG_HTTP_CLIENT_CA_PATH'],
cert: process.env['CONFIG_HTTP_CLIENT_CLIENT_CERT_PATH'],
key: process.env['CONFIG_HTTP_CLIENT_CLIENT_KEY_PATH'],
},
}
Checks included in the provider:
running
state.
running
.pass
.undefined
.service
.{
"[mdf-http-client:status]": [
{
"status": "pass",
"componentId": "00000000-0000-0000-0000-000000000000",
"observedValue": "running",
"componentType": "service",
"output": undefined,
},
],
}
undefined
): Base URL for the HTTP client requests.undefined
): Time in milliseconds before the request is considered a timeout.undefined
): Username for the HTTP client authentication, if username is set, password must be set too.undefined
): Password for the HTTP client authentication if password is set, username must be set too.false
): Keep sockets around in a pool to be used by other requests in the future.undefined
): Time in milliseconds before the keep alive feature is enabled.1000
): When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Only relevant if keepAlive is set to true.Infinity
): Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity.Infinity
): Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.256
): Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true.true
): Reject unauthorized TLS certificates.undefined
): Path to the CA certificate file.undefined
): Path to the client certificate file.undefined
): Path to the client key file.Copyright 2024 Mytra Control S.L. All rights reserved.
Use of this source code is governed by an MIT-style license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.