zimki | all bloggers | admin login | recent entries for Tom Insam
 
XMLRPC in Zimki

Tom Insam on Wed Feb 14 2007 10:11:10 GMT+0000 (BST)

Some time ago, I implemented an XMLRPC server for my django-based blog. It was pretty simple to do, and I really enjoy being able to write pages using local GUI tools. I wanted to see if I could do the same thing for Zimki.

Unlike my django experience, when I had someone else's XMLRPC engine to build on, I needed to write my own this time around. Luckily the spec is very readable, and Zimki has really good XML support. These two factors made it surprisingly easy to write. I've published it into the Zimki library realm, and you can peruse the source code here. If you want to use the library yourself, simply:

  zimki.library.require('library', 'xmlrpc.js');

Then to use it as a client,

  // create a client object, passing the endpoint of the XMLRPC
  // server we want to call
  var client = new XMLRPC('http://betty.userland.com/RPC2');

  // call a remote method
  var result = client.call( "examples.getStateName", [ 41 ] );
  // "South Dakota"

This call will throw an exception if the remote server returns an error response, or the returned data structure if not.

To run an XMLRPC server, I've added a method to the 'zimki' global object:

  zimki.publishXMLRPC('/xmlrpc_path', {
    'method.name':function(args) { ... },
    'another.method.name':function(args) { ... }
  });

The keys of the Object passed as the second parameter are the methods supported by the endpoint, passed as the first parameter. The path '/xmlrpc_path' on your realm will now act as an XMLRPC server, dispatching requests to those methods.

Now this is public, you can write your own XMLRPC servers and clients. Of course, Zimki already provides the publishService method for writing more RESTian XML services, but sometimes it's nice to not worry about the transport layer, and just move data.

I'm really liking (and hating, when it behaves oddly) E4X. It let me write an XMLRPC server in an afternoon. Zimki can produce 3 sorts of RSS feed from just a list of instances using it. The built-in REST XML server service we provide uses it. One of the competition entries we've received has used it to write a flickr client library. It just makes communicating with other services incredibly easy.

Anyway, I haven't got round to talking about the Metaweblog API implementation yet. I'll do that tomorrow or something.

leave a comment

name
email
comment