I finished my JSON-RPC and XML-RPC handlers for Tornado, and so I’ve thrown them up on Google Code. Now people can test my JSON-RPC v2.0 implementation on my jsonrpclib library.
Which is just what everyone was dying to do, I’m sure.
Usage is pretty simple, it’s designed to be a.) pretty transparent and b.) easily ported between XML-RPC and JSON-RPC to compare speed, network transfer, etc. times. For example, here’s the complete code for XML-RPC client (after installing Tornado and the TornadoRPC library):
from tornadorpc.xml import XMLRPCHandler
from tornadorpc import private, start_server
class Handler(XMLRPCHandler):
def add(self, x, y):
return x+y
def ping(self, obj):
return obj
@private
def private(self):
#should not get called
return False
start_server(Handler, port=8080)
To use JSON-RPC, you’d just change any instance of xml/XML to json/JSON. There are several benefits to using JSON, such as smaller transfer size, keyword arguments, notifications, etc., but to use it you are required to install my jsonrpclib implementation.
I'm getting the following error when I try to import JSONRPCHandler. This is on Python2.6, running on Ubuntu. How do I get around this?
>>> from tornadorpc.json import JSONRPCHandler
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “/usr/local/lib/python2.6/dist-packages/tornadorpc/json.py”, line 104, in <module>
class JSONRPCHandler(BaseRPCHandler):
File “/usr/local/lib/python2.6/dist-packages/tornadorpc/json.py”, line 109, in JSONRPCHandler
_RPC_ = JSONRPCParser(jsonrpclib)
File “/usr/local/lib/python2.6/dist-packages/tornadorpc/base.py”, line 51, in __init__
decode = getattr(library, 'loads')
AttributeError: 'module' object has no attribute 'loads'