JSON-RPC
JSON-RPC is a remote procedure call protocol encoded in JSON. It is a very simple protocol (and very similar to XML-RPC), defining only a handful of data types and commands. In contrast to XML-RPC or SOAP, it allows for bidirectional communication between the service and the client, treating each more like peers and allowing peers to call one another or send notifications to one another. It also allows multiple calls to be sent to a peer which may be answered out of order.
Besides using HTTP for transport, one may use TCP/IP sockets. Using sockets, one can create much more responsive web applications with JSON-RPC, compared to polling data from a service with JSON-RPC over HTTP.
As of version 2.0, XINS supports both JSON and JSON-RPC.
History
Version | Description | Dated |
---|---|---|
1.0 | Original version | 2005 |
1.1 WD | Working draft the specification is not yet released. Adds named parameters, adds specific error codes, and adds introspection functions. | 2006-08-07 |
1.1 Alt | suggestion for a simple JSON-RPC 1.1 Alternative proposal to 1.1 WD, differing on supported transport method(s) (and others). | 2007-05-06 |
2.0 | Specification proposal | 2008-03-07 |
Example
Note that the examples below are examples according to the "1.1 Working Draft", which is outdated. For details look into the JSON-RPC Google Group.
A JSON invocation is carried on an HTTP POST request where the content-type is application/json
. The format of the contents of a request might be something like that shown below.
{
"version": "1.1",
"method": "confirmFruitPurchase",
"id": "194521489",
"params": [
[ "apple", "orange", "pear" ],
1.123
]
}
The format of a response might be something like this.
{
"version": "1.1",
"result": "done",
"error": null,
"id": "194521489"
}
See also
External links
- Official JSON-RPC homepage includes a Python implementation of JSON-RPC
- [1] "Official" JSON-RPC Google Group
- JSON-RPC 1.1 Specification Current Working Draft
- JSON-RPC discussion group.
- JSON-RPC Implementation in the qooxdoo OO JavaScript application framework, including backends for Java, PHP, and perl.
- Barracuda Web Server's integrated JSON-RPC server and client online documentation.
- JSON-RPC implementation in JavaScript includes JSON-RPC over HTTP and over TCP/IP Sockets
- JSON/XML-RPC Client and Server Implementations which abstract-away the differences between JSON-RPC and XML-RPC and permit cross-site requests.
- jabsorb - A lightweight Ajax/Web 2.0 JSON-RPC Java framework that extends the JSON-RPC protocol with additional ORB functionality such as circular references support.
- JSON-RPC implementation in Java A JavaScript to Java AJAX communications library (now merged with jabsorb.)
- Jettison - Java library
- LEWOStuff Includes Java support for JSON-RPC also with specific support for WebObjects.