Wired Up And Fired Up

      Software of distinction

Testing xml-rpc with AppleScript
Recently I was debugging an xml-rpc web service in a Java application. It wasn't a particularly onerous task, but the compile/deploy/test loop was taking it's time and, well, I was getting bored so I decided to see if I could knock together a quick and simple test application in a scripting language. I briefly looked at Perl and Python to see what would be involved and it looked simple enough, but I'm kind of a Mac fanboy and I wondered how hard it would be to do what I wanted in AppleScript.

I didn't wonder for long, AppleScript turned out to be ideal for this kind of thing due to the Apple Event Manager having built in support for both xml-rpc and Soap messages (so much so that they could almost be considered first class constructs in the language). Well, I never...

I looked around for a public xml-rpc server to write some example code for the blog with and the most commonly used one seems to be http://superhonker.userland.com - it's also quite a neat server as it accepts both xml-rpc and Soap. So, without further ado onto the code...

Calling an xml-rpc service from Applescript.

tell application "http://superhonker.userland.com/rpc2"
return call xmlrpc {method name:"examples.getStateName", parameters:25}
end tell

Returns "Missouri"

That's it! A three liner. 'parameters' is a List. So should you need to send more it's just a matter of writing something like parameters:{25, "test", etc}

Given that basic building block, I wrote some quick scripts to test the service I was debugging and got the job done a lot quicker than I was anticipating. I've always had a soft spot for AppleScript, but occasionally it does something stunning that makes your day ten times better and you wonder what life would be like if you couldn't use a Mac for your development machine :)


|