My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
TwistedWeb  
Updated Jan 8, 2012 by duncan.m...@gmail.com

JSON-RPC for twisted.web

Dependencies

  • Twisted
  • simplejson
  • setuptools

Background

We 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.

Import

This 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 jsonrpc

If not, then you can simply use the standard import:

>>> from adytum.twisted.web2 import jsonrpc

Usage

This 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

Powered by Google Project Hosting