# sjmp

> Simple JSON Message Protocol

Latest version **2.0.5** (published 2017-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install sjmp
pnpm add sjmp
yarn add sjmp
bun add sjmp
```

## 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.5 |
| Published | 2017-01-07 |
| First published | 2016-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexander Sedov |
| Maintainers | imp |

## Links

- npm: https://www.npmjs.com/package/sjmp
- Repository: https://github.com/impomezia/sjmp-node
- Homepage: https://github.com/impomezia/sjmp-node#readme
- Issues: https://github.com/impomezia/sjmp-node/issues
- npm.io page: https://npm.io/package/sjmp

## Recent versions

- 2.0.5 (latest) — 2017-01-07
- 2.0.2 — 2017-01-07
- 2.0.1 — 2017-01-06
- 2.0.0 — 2017-01-06
- 1.2.0 — 2016-05-23
- 1.1.3 — 2016-04-19
- 1.1.2 — 2016-04-17

## README

# Simple JSON Message Protocol (SJMP) #

**Attention it is a working draft specification and compatibility can be broken at any time.**

Very simple JSON messages protocol. All packets are serialized in array.
Designed for request/reply and publish/subscribe patterns.

## Request/Reply

### Request structure

* **[0]** `{Number}`        Packet type, always `1`
* **[1]** `{String}`        Method and resource name.
* **[2]** `{String}`        Unique message ID.
* **[3]** `{*}`             Payload.
* **[4]** `{Number|String}` Optional date or ETag.
* **[5]** `{Object}`        Optional headers.

Method shortcuts:

```js
const METHODS_REVERSE = {
  '<': 'get',
  '?': 'search',
  '+': 'post',
  '=': 'put',
  '-': 'delete',
  '&': 'sub',
  '~': 'unsub'
};
```

Example: `"<account"` equal get account.  


### Reply structure

* **[0]** `{Number}`        Reply status, correspond with HTTP status codes.
* **[1]** `{String}`        Method and resource name, equal with request.
* **[2]** `{String}`        Unique message ID, equal with request.
* **[3]** `{*}`             Payload.
* **[4]** `{Number|String}` Optional date or ETag.
* **[5]** `{Object}`        Optional headers.

## Publish/Subscribe
### Event structure

* **[0]** `{Number}`        Packet type, always `2`.
* **[1]** `{String}`        Event type and resource name.
* **[2]** `{String}`        Unique message ID.
* **[3]** `{*}`             Payload.
* **[4]** `{Number|String}` Optional date or ETag.
* **[5]** `{Object}`        Optional headers.

Event types

* `=` **modified** - Notification of change a resource, usually after **put** request.
* `+` **added** - Notification of add a resource, usually after **post** request.
* `-` **deleted** - Notification of delete a resource, usually after **delete** request.

## Usage ##

```js
const sjmp = require('sjmp');

console.log(sjmp.request({
  method: 'post',
  resource: 'some/resource',
  date: 1395591341000,
  id: 'iddqd',
  body: "request body"
}));
// [1,"+some/resource","iddqd","request body",1395591341000]
```

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