The Well-Formed Web

Exploring the limits of XML and HTTP

Bulu

Bulu, the server-side code for RESTLog, is now available. This is a Python script released under the MIT license that I have tested under Apache on Windows and Linux. It implements the interface described in The RESTLog Interface. Note that it is not very useful without the client, which I will be publishing in a few days. I am making it available now as reference material for the descriptions of its operation.

Before diving into the description of Bulu.cgi you may want to take a look at the CGI Specification if you are unfarmiliar with how information is passed from the web server to a CGI application. By the description of the interface for RESTLog, particularly the table that summarizes it, incoming requests need to be dispatched based on URL, Verb and Type. (Note that when I refer to Type I am talking about the abbreviated types in Type Mappings Table.) The URL can be that of the CGI script alone or it can be the name of the CGI script with a path extension of the itemID. Inside a CGI script the path extension information is passed in via the PATH_INFO environment variable. Verb can be one of the standard HTTP verbs GET, PUT, POST and DELETE and this is passed in via the REQUEST_METHOD environment variable. Lastly the Type can be selected via content negotiation or set by a query string. That's a lot of information to consider when dispatching requests so in RESTLog it is broken down into two phases. For the first phase requests are segregated based on the URI they pertain to. Requests for the base URL Bulu.cgi are passed to the class RootDispatch to be handled. Requests for the item URL Bulu.cgi/itemID are passed to the ItemDispatch class.

Both RootDispatch and ItemDispatch derive from the same base class BaseHttpDispatch which has a single member function, dispatch(self, verb, mime_type) which dispatches requests based on the Verb and Type of the message. The dispatching is done by introspection (aka reflection for those familiar with .Net nomenclature) where the dispatch function looks for a member function of the class that has the name Verb_Type. If a match isn't found then it looks for the function with the name Verb. If none of those exist then an error code is returned. For example, if you POST an XML document to Bulu.cgi then RootDispatch will be instanced and when BaseHttpDispatch.dispatch is called it will first look for RootDispatch.POST_xml and if it fails to find that it will look for the member function RootDispatch.POST. In Bulu.cgi RootDispatch implements POST_xml and it is this function that is called when the client creates a new story by POSTing the item as XML to the URL Bulu.cgi.

Tomorrow I will cover the simplistic templating mechanisms that RESTLog employs to format the content.

2002-11-11 22:42 Comments (1)


nama saya adalah hakimi saya bayak bulu
saya anak ke 1000

Posted by on 2004-03-01 21:26