Module @mdf.js/http-client-provider

@mdf.js/http-client-provider

Node Version Typescript Version Known Vulnerabilities Documentation

netin

Mytra Development Framework - @mdf.js/http-client-provider

Typescript tools for development

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:

  • status: Due to the nature of the HTTP client, the status check is not implemented. The provider is always in running state.
    • observedValue: running.
    • status: pass.
    • output: undefined.
    • componentType: service.
{
"[mdf-http-client:status]": [
{
"status": "pass",
"componentId": "00000000-0000-0000-0000-000000000000",
"observedValue": "running",
"componentType": "service",
"output": undefined,
},
],
}
  • CONFIG_HTTP_CLIENT_BASE_URL (default: undefined): Base URL for the HTTP client requests.
  • CONFIG_HTTP_CLIENT_TIMEOUT (default: undefined): Time in milliseconds before the request is considered a timeout.
  • CONFIG_HTTP_CLIENT_AUTH_USERNAME (default: undefined): Username for the HTTP client authentication, if username is set, password must be set too.
  • CONFIG_HTTP_CLIENT_AUTH_PASSWORD (default: undefined): Password for the HTTP client authentication if password is set, username must be set too.
  • CONFIG_HTTP_CLIENT_KEEPALIVE (default: false): Keep sockets around in a pool to be used by other requests in the future.
  • CONFIG_HTTP_CLIENT_KEEPALIVE_INITIAL_DELAY (default: undefined): Time in milliseconds before the keep alive feature is enabled.
  • CONFIG_HTTP_CLIENT_KEEPALIVE_MSECS (default: 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.
  • CONFIG_HTTP_CLIENT_MAX_SOCKETS (default: Infinity): Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity.
  • CONFIG_HTTP_CLIENT_MAX_SOCKETS_TOTAL (default: 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.
  • CONFIG_HTTP_CLIENT_MAX_SOCKETS_FREE (default: 256): Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true.
  • CONFIG_HTTP_CLIENT_REJECT_UNAUTHORIZED (default: true): Reject unauthorized TLS certificates.
  • CONFIG_HTTP_CLIENT_CA_PATH (default: undefined): Path to the CA certificate file.
  • CONFIG_HTTP_CLIENT_CLIENT_CERT_PATH (default: undefined): Path to the client certificate file.
  • CONFIG_HTTP_CLIENT_CLIENT_KEY_PATH (default: 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.

Namespaces

HTTP