|
TwistedWeb
JSON-RPC for twisted.webDependencies
BackgroundWe needed a twisted-based JSON-RPC server for making remote calls from an AJAX app. This allowed us to change our XML-RPC server to a JSON-RPC server with a simple import change. Since there is no xmlrpclib equivalent for JSON-RPC, we had to make our own. It's very simple and minimal. We copied error codes and some exception classes from the xmlrpclib in the python standard library, and then we over-rode the simplejson.loads and simplejson.dumps methods with our own module-level functions (basically making a few additions for exception handling). The original tests from twisted.web.xmlrpc were also included/adapted and pass successfully. ImportThis is a stand-alone package that uses the adytum namespace, so if you have any other adytum code installed, you'll need to use setuptools' pkg_resource module: >>> from pkg_resources import require
>>> require('Adytum-Twisted')
>>> from adytum.twisted import jsonrpcIf not, then you can simply use the standard import: >>> from adytum.twisted.web2 import jsonrpc UsageThis is a direct copy from twisted.web.xmlrpc and you use it identically, substituting JSONRPC and jsonrpc everywhere you see XMLRPC and xmlrpc. Here's a link to the docs: http://twistedmatrix.com/projects/web/documentation/howto/xmlrpc.html |