4.3.0 • Published 1 year ago

@sealsystems/request-service v4.3.0

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

@sealsystems/request-service

Makes a request to a service, using consul for discovery and lookup.

Installation

$ npm install @sealsystems/request-service

Quick start

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

const requestService = require('@sealsystems/request-service');

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

To create a HTTP/HTTPS request to an instance of a service use:

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

const req = await requestService({ consul, service: 'myService' });

req.on('connect', () => {
  console.log('Connected to service!');
});

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

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

propertytypedescription
consulrequired objectConsul client for service discovery
servicerequired stringName of the service to access
headersoptional objectAdditional HTTP/HTTPS headers
methodoptional stringHTTP/HTTPS method, default POST
pathoptional stringURL-path to access, default /
responseTypeoptional stringRead JSON response and return it as object. Possible value: json
jsonoptional objectOnly valid together with responseType. Send object given in json property to service

Here is an example of a more complete options object:

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

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

HTTP and HTTPS

The protocol used for a connection depends on the target (the service resides in the local or a remote host) 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.

Used protocol:

TLS_UNPROTECTEDlocal serviceremote service
'world'HTTPHTTP
'loopback'HTTPHTTPS
'none'HTTPSHTTPS
4.3.0

1 year ago

4.2.0

1 year ago

4.1.7

1 year ago

4.1.6

1 year ago

4.1.5

2 years ago

4.1.4

2 years ago

4.1.3

2 years ago

4.1.2

2 years ago

4.1.0

2 years ago

4.1.1

2 years ago

4.0.32

2 years ago

4.0.31

3 years ago

4.0.30

3 years ago

4.0.29

3 years ago

4.0.27

3 years ago

4.0.28

3 years ago

4.0.26

4 years ago

4.0.25

4 years ago

4.0.24

4 years ago

4.0.23

4 years ago

4.0.19

4 years ago

4.0.21

4 years ago

4.0.20

4 years ago

4.0.22

4 years ago

4.0.16

4 years ago

4.0.15

4 years ago

4.0.18

4 years ago

4.0.17

4 years ago

4.0.10

4 years ago

4.0.12

4 years ago

4.0.11

4 years ago

4.0.14

4 years ago

4.0.13

4 years ago

4.0.9

4 years ago

4.0.8

5 years ago

4.0.7

5 years ago

4.0.6

5 years ago

4.0.5

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.4.0

6 years ago

3.3.7

6 years ago

3.3.6

6 years ago

3.3.5

6 years ago

3.3.4

6 years ago

3.3.3

6 years ago

3.3.2

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.2.28

7 years ago

2.2.27

7 years ago

2.2.26

7 years ago