Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Update actions/events communication format to JSON-RPC #5918

Closed
shuse2 opened this issue Oct 28, 2020 · 5 comments · Fixed by #5948
Closed

Update actions/events communication format to JSON-RPC #5918

shuse2 opened this issue Oct 28, 2020 · 5 comments · Fixed by #5948
Assignees
Milestone

Comments

@shuse2
Copy link
Collaborator

shuse2 commented Oct 28, 2020

Description

Update communication schema of actions and events to be in the format of JSON-RPC v2 referencing in action.ts and event.ts

Motivation

Enable message communication to be transport agnostic by introducing JSON-RPC.
JSON-RPC node communication is a standard in the industry, and as actions and events are going to be exposed for API client, it should follow the standard.

Why update only the action and events format to JSONRPC?
Why the new APIClients IPC/WS does not respond in JSONRPC format?

Acceptance Criteria

  • invoke, subscribe function interface should not be changed.

Additional Information

Related issue #5919

@ManuGowda
Copy link
Contributor

Request object

{ jsonrpc, method, params, id }

jsonrpc:

A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".

method:

A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used for anything else.

params:

A Structured value that holds the parameter values to be used during the invocation of the method. This member MAY be omitted.

id:

An identifier established by the Client that MUST contain a String, Number, or NULL value if included. If it is not included it is assumed to be a notification. The value SHOULD normally not be Null [1] and Numbers SHOULD NOT contain fractional parts [2]

@ManuGowda
Copy link
Contributor

Response object

{ jsonrpc, result, error, id }

jsonrpc:

A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".

result

This member is REQUIRED on success.
This member MUST NOT exist if there was an error invoking the method.
The value of this member is determined by the method invoked on the Server.

error

This member is REQUIRED on error.
This member MUST NOT exist if there was no error triggered during invocation.
The value for this member MUST be an Object as defined in section 5.1.

id

This member is REQUIRED.
It MUST be the same as the value of the id member in the Request Object.
If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.

@ManuGowda
Copy link
Contributor

Batch

To send several Request objects at the same time, the Client MAY send an Array filled with Request objects.

The Server should respond with an Array containing the corresponding Response objects, after all of the batch Request objects have been processed. A Response object SHOULD exist for each Request object, except that there SHOULD NOT be any Response objects for notifications. The Server MAY process a batch rpc call as a set of concurrent tasks, processing them in any order and with any width of parallelism.

The Response objects being returned from a batch call MAY be returned in any order within the Array. The Client SHOULD match contexts between the set of Request objects and the resulting set of Response objects based on the id member within each Object.

If the batch rpc call itself fails to be recognized as an valid JSON or as an Array with at least one value, the response from the Server MUST be a single Response object. If there are no Response objects contained within the Response array as it is to be sent to the client, the server MUST NOT return an empty Array and should return nothing at all.

request
[
   {"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3}
   {"jsonrpc": "2.0", "method": "get_data", "id": "9"}
]
response
[
   {"jsonrpc": "2.0", "result": 19, "id": 3}
   {"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"}
]

@ManuGowda
Copy link
Contributor

Notification

A Notification is a Request object without an "id" member. A Request object that is a Notification signifies the Client's lack of interest in the corresponding Response object, and as such no Response object needs to be returned to the client. The Server MUST NOT reply to a Notification, including those that are within a batch request.

Notifications are not confirmable by definition, since they do not have a Response object to be returned. As such, the Client would not be aware of any errors (like e.g. "Invalid params","Internal error").

Request

[
        {"jsonrpc": "2.0", "method": "notify_sum", "params": [1,2,4]},
        {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}
]

No response

@ManuGowda
Copy link
Contributor

Error object

When a rpc call encounters an error, the Response Object MUST contain the error member with a value that is a Object with the following members:

code
A Number that indicates the error type that occurred.
This MUST be an integer.
message
A String providing a short description of the error.
The message SHOULD be limited to a concise single sentence.
data
A Primitive or Structured value that contains additional information about the error.
This may be omitted.
The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).

The error codes from and including -32768 to -32000 are reserved for pre-defined errors. Any code within this range, but not defined explicitly below is reserved for future use

code message meaning
-32700 Parse error Invalid JSON was received by the server.An error occurred on the server while parsing the JSON text.
-32600 Invalid Request The JSON sent is not a valid Request object.
-32601 Method not found The method does not exist / is not available.
-32602 Invalid params Invalid method parameter(s).
-32603 Internal error Internal JSON-RPC error.
-32000 to -32099 Server error Reserved for implementation-defined server-errors.

shuse2 added a commit that referenced this issue Nov 5, 2020
Update actions/events communication format to JSON-RPC - Closes #5918
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants