Vadim Dalecky5 years agoJSON-RPC Compact is a variation of JSON-RPC 2.0 protocol and further improvement over JSON-RPC Light protocol. JSON-RPC Compact follows the same semantics as JSON-RPC but the messages are encoded in a more compact format.
Request message is a 3-tuple, which consists of: (1) message ID; (2) remote method name; (3) JSON parameters. It can also be a 2-tuple if the JSON parameters are omitted, e.g. the method has no arguments.
Message ID must be a positive integer. Usually it is an incrementing counter, which starts from 1 and is incremented with every request.
Remote method name is a string. In must be at least 1 character long, and no longer than 128 characters.
JSON parameters is the third member of the tuple and is a JSON object which represents the arguments for the remote method.
Examples:
Success response message is a 3-tuple. Tuple members are as follows: (1) first member is always 0 and signifies a successful response; (2) second member is the message ID of the request; (3) third member is the response payload in JSON format.
Success response might also be a 2-tuple if it is not expected to ever return anything, i.e. it is a method with side-effects only. If the method is expected to return some response at least in some situations, the third member of the 3-tuple should always be present in every response message.
Examples:
Error response message is a 3-tuple. It is always a 3-tuple and cannot be be reduced to 2-tuple. Error message 3-tuple is specified as follows: (1) first member is always set to -1; (2) second member is the message ID of the request message; (3) is the error in JSON format.
The third tuple member is an arbitrary JSON value, specific to the application. Usually it is an object with at least "message" field.
Notification message is a one way message, for which no direct response is expected (at the level of this protocol, although you can still use it to implement a higher level protocol).
Notification message is a 2-tuple, which consists of: (1) first member is a string specifying a remote message; (2) second member is JSON payload.
The first string member must be at least 1 character long and no more than 128 characters in length.
Notification message may also be a 1-tuple, in which case semantically it is treated as a notification message without arguments.
Examples:
Request message:
Success response message:
Error response message:
Notification message: