2.0.5 • Published 7 years ago

sjmp v2.0.5

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

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:

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

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]
2.0.5

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.0

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago