2.3.3 • Published 6 years ago

seal-request-service v2.3.3

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

seal-request-service

CircleCI AppVeyor

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

Installation

$ npm install seal-request-service

Quick start

First you need to add a reference to seal-request-service within your application.

var requestService = require('seal-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:

requestService({ service: 'myService' }, (err, req) => {
  if (!err) {
    throw new Error('An error occurred while connecting to the service.');
  }

  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
servicerequired stringName of the service to access
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:

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

The callback function given as the second parameter will be called when a connection to a instance of the service could be established. In this case, the err parameter is null and the req parameter contains a http.ClientRequest object for further use. Otherwise, the err parameter contains an Error object with further details about the problem.

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 seal-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

Running the build

To build this module use roboter.

$ bot
2.3.3

6 years ago

2.3.2

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.25

7 years ago

2.2.24

7 years ago

2.2.23

7 years ago