npm install sjmpAttention 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.
* [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: "
* [0] {Number} Reply status, correspond with HTTP status codes.{String}
* [1] Method and resource name, equal with request.{String}
* [2] Unique message ID, equal with request.{}
[3] Payload.{Number|String}
* [4] Optional date or ETag.{Object}
* [5] Optional headers.
* [0] {Number} Packet type, always 2.{String}
* [1] Event type and resource name.
{String}
* [2] Unique message ID.{}
[3] Payload.{Number|String}
* [4] Optional date or ETag.{Object}
* [5] 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.
`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]
``