# @superbalist/js-pubsub-http

> An HTTP adapter for the js-pubsub package.

Latest version **2.0.0** (published 2017-07-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @superbalist/js-pubsub-http
pnpm add @superbalist/js-pubsub-http
yarn add @superbalist/js-pubsub-http
bun add @superbalist/js-pubsub-http
```

## 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 | 2.0.0 |
| Published | 2017-07-18 |
| First published | 2017-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Superbalist.com a division of Takealot Online |
| Maintainers | bradwhittington, zoidbergwill, matthewgoslett |
| Keywords | pubsub, google, http, rest |

## Links

- npm: https://www.npmjs.com/package/@superbalist/js-pubsub-http
- Repository: https://github.com/Superbalist/js-pubsub-http
- Homepage: https://github.com/Superbalist/js-pubsub-http#readme
- Issues: https://github.com/Superbalist/js-pubsub-http/issues
- npm.io page: https://npm.io/package/@superbalist/js-pubsub-http

## Dependencies (3)

- [request](https://npm.io/package/request.md) ^2.81.0
- [@superbalist/js-pubsub](https://npm.io/package/@superbalist/js-pubsub.md) ^3.0.0
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.4

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2017-07-18
- 1.0.1 — 2017-05-23
- 1.0.0 — 2017-05-23

## README

# @superbalist/js-pubsub-http

An HTTP adapter for the [js-pubsub](https://github.com/Superbalist/js-pubsub) package.

[![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist)
[![Build Status](https://img.shields.io/travis/Superbalist/js-pubsub-http/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/js-pubsub-http)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![NPM Version](https://img.shields.io/npm/v/@superbalist/js-pubsub-http.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub-http)
[![NPM Downloads](https://img.shields.io/npm/dt/@superbalist/js-pubsub-http.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub-http)

This adapter assumes that you have a HTTP service which accepts an array of messages POSTed to a
/messages/(channel) end-point.

## Installation

```bash
npm install @superbalist/js-pubsub-http
```
    
## Usage
```node
'use strict';

let pubsub = require('@google-cloud/pubsub');
let GoogleCloudPubSubAdapter = require('@superbalist/js-pubsub-google-cloud');
let HTTPPubSubAdapter = require('@superbalist/js-pubsub-http');

process.env.GOOGLE_APPLICATION_CREDENTIALS = '/path/to/your-gcloud-key.json';

// create the underlying adapter which is going to be decorated
let client = pubsub({
  projectId: 'your-project-id-here',
});

let googleCloudAdapter = new GoogleCloudPubSubAdapter(client);

// now create our decorator
// the decorator will proxy subscribe calls straight to the googleCloudAdapter
// publish calls will be POSTed to the service uri
let adapter = new HTTPPubSubAdapter('http://127.0.0.1', googleCloudAdapter);

adapter.subscribe('my_channel', (message) => {
  console.log(message);
  console.log(typeof message);
});

// consume messages
// note: this is a blocking call
adapter.subscribe('my_channel', (message) => {
  console.log(message);
  console.log(typeof message);
});

// publish messages
adapter.publish('my_channel', {first_name: 'Matthew'});
adapter.publish('my_channel', 'Hello World');

// publish multiple messages
let messages = [
  'message 1',
  'message 2',
];
adapter.publishBatch('my_channel', messages);
```

## TODO

* Add unit tests

## Examples

The library comes with [examples](examples) for the adapter and a [Dockerfile](Dockerfile) for
running the example scripts.

Run `make up`.

You will start at a `bash` prompt in the `/usr/src/app` directory.

If you need another shell to publish a message to a blocking consumer, you can run `docker-compose run js-pubsub-http /bin/bash`

To run the examples:
```bash
$ ./run_consumer.sh
$ ./run_publisher.sh (in a separate shell)
```

---
_Source: https://npm.io/package/@superbalist/js-pubsub-http · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
