JSONRPC

Inherits: Object

Creates and processes JSON-RPC objects.

Description

JSON-RPC is a standard which wraps a method call in a JSON object that can be sent between systems. Request, notification and response objects have a defined structure that enable methods with arguments to be called and results to be returned. This class implements that standard using a Dictionary.

Methods

Dictionary

make_notification ( String method, Variant params ) const

Dictionary

make_request ( String method, Variant params, Variant id ) const

Dictionary

make_response ( Variant result, Variant id ) const

Dictionary

make_response_error ( int code, String message, Variant id=null ) const

Variant

process_action ( Variant request, bool unused=true )

String

process_string ( String request_string )

void

set_scope ( String scope, Object target )

Enumerations

enum ErrorCode:

  • PARSE_ERROR = -32700

  • INVALID_REQUEST = -32600

  • METHOD_NOT_FOUND = -32601

  • INVALID_PARAMS = -32602

  • INTERNAL_ERROR = -32603

Method Descriptions

Creates a JSON-RPC Notification object as a dictionary. A JSON-RPC Notification object is sent to a server to call method. The method will be called with params arguments passed as an Array or Dictionary.

Notification objects are sent to a server when a response is not required. If a response is required, then use make_request to create a Request object instead.

If scopes are used, method will be of the form "scope/method". See set_scope for specifying the object against which the method should be called.


Creates a JSON-RPC Request object as a dictionary. A JSON-RPC Request object is sent to a server to call method. The method will be called with params arguments passed as an Array or Dictionary. The id uniquely identifies this request. The server is expected to send a response with the same ID.

Request objects are sent to a server with the expectation of a response. If a response is not required, then use make_notification to create a Notification object instead.

If scopes are used, method will be of the form "scope/method". See set_scope for specifying the object against which the method should be called.


Creates a JSON-RPC Response object as a dictionary. A JSON-RPC Response object is sent by a server after processing a Request Object. The result is the return value of the method called. The id is the same id that was sent with the Request object.


Creates a JSON-RPC Response error object as a dictionary. A JSON-RPC Response error object is sent by a server if a Request object results in an error. The code indicates the type of error that occurred. It must be one of the ErrorCode constants. The message is a short description of the error. It should be a concise single sentence. The id is the same id that was sent with the Request object.


Processes a request: a JSON-RPC Request or Notification object passed as a Dictionary or an Array of JSON-RPC Dictionary objects. If it received a JSON-RPC Request object, it returns a JSON-RPC Response object as a Dictionary or an Array of JSON-RPC Response objects.

The unused argument is not used.

Note: Only methods of objects added using set_scope or declared in the class extended from JSONRPC are processed.


Processes a request_string: a JSON-RPC Request or Notification object passed as a JSON String. If it received a JSON-RPC Request object, it returns a JSON-RPC Response object as a JSON String.

Note: Only methods of objects added using set_scope or declared in the class extended from JSONRPC are processed.


Adds a target object, whose methods can be called via a JSON-RPC Request object. The object is identified via the scope name. Methods are called using the form "scope/method".