This plugin implements the JSONRPC class with a send function that can be used for performing JSON-RPC calls. The plugin adheres supports all currently available version of the JSON-RPC specification, but the implementation may be partial or inaccurate in some cases.
The code has been completely rewritten 3 times, but this release (0.4) will be the foundation of future releases, and I will stabilize the API until 1.0.
The API of this plugin has changed a lot since the initial release. The original idea was to simplfy JSON-RPC calls so they can be used almost like a plain function call. The JSON-RPC setup has two parts: configuration and call. Configuration may look like this:
var myRpcCaller = new JSONRPC({ url: '/serivces/jsonrpc', methodname: 'mymethod', onSuccess: function(response){ console.log(response) } });
The above code creates a myRpcCaller object, that is bound to remote mymethod method. This binding allows us to call the remote method passing only parameters and callbacks, without repeating the method multiple times:
myRpcCaller.send({params: "some text", onSuccess: function(){ console.log('we did it!'); } });
Options for JSON-RPC configuration are as follows:
The JSONRPC class has four events and you can specify the matching callbacks.
You send JSON-RPC requests using the send function. This function takes a single object as is argument. If any of the object properties matches the one specified in the configuration, it will override the configuration. The object can have the following properties:
I thank the following people for their invaluable advice, code, and generally being cool guys to talk to (in no particular order).
Report any issues to the github issue tracker.
The first version of the specification requires that the parameters are specified inside an array. JSONRPC plugin doesn't check for this, so it is your job to ensure this. Later version of the specification also allow objects to be used in place of arrays, which makes it possible to use named parameters.
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus