3.2.1 • Published 1 year ago

@sealsystems/connect-service v3.2.1

Weekly downloads
20
License
MIT
Repository
github
Last release
1 year ago

@sealsystems/connect-service

Connects to a service with given host name and port number.

Installation

$ npm install @sealsystems/connect-service

Quick start

First you need to add a reference to @sealsystems/connect-service within your application.

const connectService = require('@sealsystems/connect-service');

Please note: A connection to consul must already exist before you can use the module.

To create a HTTP/HTTPS connection to an instance of a service (e.g. myService), use:

const consul = require('@sealsystems/consul');
consul.connect(...);

const client = await connectService({
  service: 'myService',
  path: '/job',
  consul
}, {
  name: 'hostname',
  port: 3000
});

client.on('response', (response) => {
  console.log(`Response status: ${response.statusCode}`);
});

client.write('Hello service!');
client.end();

The first parameter is an options object that can contain the following properties:

propertytypedescription
servicerequired stringName of the service to access
consulrequired objectInitialized instance of node-consul
headersoptional objectAdditional HTTP/HTTPS headers
methodoptional stringHTTP/HTTPS method, default POST
pathoptional stringURL-path to access, default /

Here is an example of a more complete options object:

const options = {
  headers: {
    'content-type': 'application/json'
  },
  method: 'POST',
  path: '/url/path',
  service: 'myService',
  consul
};

Second parameter is the host name and port number. Example:

const host = {
  name: 'hostname',
  port: 3000
};

The return value client contains a http.ClientRequest object for further use.

HTTP and HTTPS

The protocol used for a connection depends on the target (local or remote) and the value of the environment variable TLS_UNPROTECTED. The TLS certificates provided by @sealsystems/tlscert will be used for HTTPS connections. It is not possible to override the chosen protocol.

Running the build

To build this module use roboter.

$ bot
3.2.1

1 year ago

3.2.0

2 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

4 years ago

3.0.18

4 years ago

3.0.17

4 years ago

3.0.16

4 years ago

3.0.12

4 years ago

3.0.13

4 years ago

3.0.11

4 years ago

3.0.14

4 years ago

3.0.15

4 years ago

3.0.9

4 years ago

3.0.10

4 years ago

3.0.8

4 years ago

3.0.7

4 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.3.0

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago