JSON-RPC

JSON -RPC JavaScript Object Notation ( Remote Procedure Call) is a protocol for calling remote methods in computer systems, similar to XML -RPC ( the data is sent in JSON instead of XML). The specification has been taken to ensure that JSON -RPC as possible does not contain unnecessary complexity and can be used via various communication protocols. This can be used very flexibly. In addition, the protocol supports asynchronous communication, since all requests and responses contain an ID, which allows an easy mapping of responses to requests acc.

JSON -RPC 1.0 requests allowed in both directions ( peer -to-peer ), JSON -RPC 2.0 uses a client - server model.

  • 2.1 Version 2.0
  • 2.2 Version 1.0

Operation

Inquiry

A JSON - RPC call consists of a JSON object that is sent from the client to a server. Possible request types are

  • Request ( engl. request): The server should provide an answer.
  • Notification (English notification): one-way communication from the server no response is expected.
  • Batch Request ( engl. stack request): Multiple requests ( notifications or requests) are sent together. (Available from version 2.0)

In the following table, the constituents of a request object are listed.

A Notification is characterized in that:

  • JSON -RPC version 2.0: id is missing
  • JSON -RPC version 1.0: id is null

Reply

In the case of a request, the server sends for execution of the requested method a response as JSON object back to the client. The components of a response object are listed in the following table.

  • Version 2.0: this field is omitted.
  • Version 1.0: This field has the value zero.
  • Version 2.0: this field is omitted.
  • Version 1.0: This field has the value zero.

If the server receives a notification, it performs the specified method, but sends no response. If it receives a batch request, it executes the methods listed, and sends a batch response (ie, the answers to all requests in the batch request in a message ).

Examples

> For a message from the client to the server, and <- - In these examples is reversed.

Version 2.0

A simple example of a request and a response

-> {" Jsonrpc ": " 2.0", "method": " gibAus ", " params ": {" message ": " Hello JSON -RPC "}, " id": 1} <- {" Jsonrpc ": " 2.0", "result": " Hello JSON -RPC ", " id": 1} More examples can be found at the end of the JSON -RPC 2.0 specification.

Version 1.0

A simple example of a request and a response

- > { "Method": " gibAus ", " params ": [" Hello JSON -RPC " ], "id": 1} <- { "Result": " Hello JSON -RPC ", " error": null, " id": 1} This example shows part of the communication in a chat application. The chat service sends a notification for each message that is to receive the client. The client sends a request to send a message and expect a positive feedback to know that the message was posted.

... - > { "Method": " veröffentlicheNachricht ", " params ": [" Hello everyone! " ], "Id": 99 } <- { "Result": 1, " error": null, " id": 99 } <- { "Method": " is found message ", " params ": [" user1 ", " We were talking just " ], "id": null} <- { "Method": " is found message ", " params ": [" user3 ", "I have to go now, bye " ], "id": null} - > { "Method": " veröffentlicheNachricht ", " params ": [" I have a question! " ], "Id": 101 } <- { "Method": " ändereStatus ", " params ": [" absent ", " user3 " ], "id": null} <- { "Result": 1, " error": null, " id": 101 } ... Revision history

The first version of the JSON -RPC comes from 2005., Version 2.0 was adopted in 2010.

Implementations

JSON - RPC is implemented in different programming languages ​​, including JavaScript, C , C, C #, Java, Python, and PHP. However, since JSON consists of Unicode characters, JSON -RPC can be relatively easily implemented in other programming languages.

454689
de