Web Services Progress

As I work on the Dice Server, I’m also building a Web Services API to take advantage of the Web 2.0 / Ajax / Buzzword Soup tech that is available. Of course, I feel the need to roll my own; I hate using technology that I haven’t worked on. If I have to maintain it, I need to know how it works.

On the server, I’m relying on Ruby/FastCGI. Not Rails. I used Rails for the Tewksbury SpedPAC site, but I don’t know enough about the inner workings to feel comfortable relying on it. Nor do I care to read reams of Ruby code to gain that understanding. Throw in a memory leak issue with Rails/FastCGI and I’d just as soon roll my own thinner solution.

I have two fcgi scripts written: index.fcgi and services.fcgi. Index.fcgi will handle page navigation requests while services.fcgi will be the services API gateway. Right now, the scripts are quite skeletal, supporting very basic session logging and basic services tests.

The browser side code is encapsulated in Ajax.js, Javascript code that is heavily based on code found in the book “Ajax in Action”. Other Javascript code supports the first Ajax test, which isn’t working quite yet.

The calling convention consists of the creating the Ajax.Requestor object with a URL (services.fcgi) and the function call string, which is passed via the HTTP POST method.

Previous partially successful attempts to write a Web Services API relied on sending and receiving XML documents via a protocol called XmlCGI, my own version of XmlRPC. While XML is quite useful as a data markup language, I don’t like the heavy overhead of trying to build and decode a function string. JSON looks more succinct, but I’m only going to use JSON for the server response as Javascript can quickly decode this via its eval() function. For the uplink, I’m going to use my own specification:

ServiceName.Function([param: value[, param: value]...])

Whereas in C/C++ programming, the function prototype defines the argument order, I’m going to rely on the fact that the function string is a string and use named arguments.

Services provided by the web server will be Ruby classes. Each such class will have a specification which will define available functions and their function prototypes, including required, optional and/or default arguments. Because I’ll be sending named arguments, order is not important. What I want most to avoid is arbitrary limitations.

The first service that I’m creating is called DebugService. The three functions are Ping(), Echo(string) and ReverseEcho(string). To use these services within Javascript, one need only do:

var requestor = new Ajax.Requestor("http://my.domain.com/services.fcgi",
            'DebugService.Echo("text string")', do_echo_callback)

where do_echo_callback is a Javascript function which will receive the response from the web service and hopefully do something intelligent with the received data.

Comments are closed.