# seal-connect-service-cl

> Connects to a service.

Latest version **1.1.0** (published 2018-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install seal-connect-service-cl
pnpm add seal-connect-service-cl
yarn add seal-connect-service-cl
bun add seal-connect-service-cl
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-04-14 |
| First published | 2018-04-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | SEAL Systems AG |
| Maintainers | stefanscherer |

## Links

- npm: https://www.npmjs.com/package/seal-connect-service-cl
- Repository: https://github.com/sealsystems/seal-connect-service
- Homepage: https://github.com/sealsystems/seal-connect-service#readme
- Issues: https://github.com/sealsystems/seal-connect-service/issues
- npm.io page: https://npm.io/package/seal-connect-service-cl

## Dependencies (4)

- [getenv](https://npm.io/package/getenv.md) 0.7.0
- [seal-log](https://npm.io/package/seal-log.md) 1.2.0
- [seal-tlscert](https://npm.io/package/seal-tlscert.md) 1.2.1
- [@sealsystems/seal-consul](https://npm.io/package/@sealsystems/seal-consul.md) 3.5.7

## Recent versions

- 1.1.0 (latest) — 2018-04-14

## README

# seal-connect-service

[![CircleCI](https://circleci.com/gh/sealsystems/seal-connect-service.svg?style=svg)](https://circleci.com/gh/sealsystems/seal-connect-service)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/d7djlcycod4jhj4i?svg=true)](https://ci.appveyor.com/project/Plossys/seal-connect-service)

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

## Installation

```bash
$ npm install seal-connect-service
```

## Quick start

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

```javascript
const connectService = require('seal-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:

```javascript
connectService({
  service: 'myService',
  path: '/job'
}, {
  name: 'hostname',
  port: 3000
}, (err, client) => {
  if (!err) {
    throw new Error('An error occurred while connecting to the service.');
  }

  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:

| property  | type            | description                        |
|-----------|-----------------|------------------------------------|
| service   | required string | Name of the service to access      |
| headers   | optional object | Additional HTTP/HTTPS headers      |
| method    | optional string | HTTP/HTTPS method, default `POST`  |
| path      | optional string | URL-path to access, default `/`    |

Here is an example of a more complete `options` object:

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

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

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

The `callback` function given as the third parameter will be called when a connection to the service could be established. In this case, the `err` parameter is `null` and the `req` parameter contains a [http.ClientRequest](https://nodejs.org/api/http.html#http_class_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 (local or remote) 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.

## Running the build

To build this module use [roboter](https://www.npmjs.com/package/roboter).

```bash
$ bot
```

---
_Source: https://npm.io/package/seal-connect-service-cl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
