Differences between revisions 1 and 2
Revision 1 as of 2005-06-15 11:15:14
Size: 2099
Editor: ZoomQuiet
Comment:
Revision 2 as of 2009-12-25 07:19:10
Size: 2103
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 43: Line 43:
Consult the [http://www.mems-exchange.org/software/quixote/doc/web-services.html web-services.txt] Consult the [[http://www.mems-exchange.org/software/quixote/doc/web-services.html|web-services.txt]]
Line 48: Line 48:
[http://internet.conveyor.com/RESTwiki/moin.cgi/FrontPage REST] is a competing application design approach [[http://internet.conveyor.com/RESTwiki/moin.cgi/FrontPage|REST]] is a competing application design approach

Problem

You want to provide an interface into your application that can be used by other programs. For example, a bug tracking system could support some way for users to write scripts that retrieve the list of bugs assigned to them.

Solution

Write an XML-RPC interface. Quixote includes a helper function in the quixote.util module that simplifies the task.

from quixote.util import xmlrpc

def rpc (request, rpc_process):
    return xmlrpc(request, rpc_process)

def rpc_process (meth, params):
    if meth == 'list_bugs':
        user, password = params
        return retrieve_bugs_for_user(user, password)
    else:
        raise RuntimeError, "Unknown XML-RPC method: %r" % meth

To call the interface implemented above from a Python script, you would use the following code:

import xmlrpclib
s = xmlrpclib.Server('http://your.server.example.com/rpc')
bugs = s.list_bugs('amk', 'password')

XML-RPC implementations are available for most other languages, so the list_bugs() method could be called from any of them.

Discussion

XML-RPC's data types are relatively limited. You can return numbers, strings, lists, and dictionaries. You can't return Python objects, complex numbers,or Python's None value (the most irritating omission).

Consult the web-services.txt documentation file included with Quixote for more information about implementing XML-RPC interfaces.

The 'RPC' stands for Remote Procedure Call, since you're basically providing a way to call a function on your server. REST is a competing application design approach that uses URLs to represent operations and queries, and therefore has certain nice properties. For example, if you have a URL representing "amk's bug list", this URL can be bookmarked, forwarded to other people, and have RDF assertions made about it, none of which are possible with XML-RPC queries.


CategoryCookbook

QuixoteCookbook/XmlRpcInterface (last edited 2009-12-25 07:19:10 by localhost)