[mod_python] restful discussion on handler

Graham Dumpleton graham.dumpleton at gmail.com
Fri May 25 19:04:26 EDT 2007


On 26/05/07, David Bear <David.Bear at asu.edu> wrote:
> recently there was some discussion of implementing a restful api using
> the publisher handler.

Strictly speaking, the publisher handler cannot be used to implement a
true REST API as it only allows GET/POST and not other HTTP method
types.

> I'm wondering if anyone has any code use the python-program handler?

The publisher handler is still a handler and is itself one example of
doing dispatching which you can look at, it probably just does more
than what you are after by what you have said before. Doesn't mean you
can't learn from it.

> I would like to see how to properly handle parsing the req url and
> dispatching from that. I liked the way publisher would provide a url
> to call a function. It seems that it would just be safer to have one
> functions 'handler' that would be used as the single entry point to
> all 'dispatching'.

Overall am still not sure how you are expecting the URL mapping to
work. There are few levels one could go to.

The first is to only map as far as the file. For example, a URL would
map to a standard handler() function in the file. If there is
additional path information after the portion of the URL that mapped
to the file, it would be up to the handler in the file to deal with.

The second is for the dispatcher to take the additional path
information and then map that into objects contained within the file.
One could when doing this one could allow functions to be called with
standard handler prototype and response, or one could could do like
publisher and transform form arguments into arguments and change how
the return value is treated. The publisher handler also allows one to
reference variables and have the string representation of them
changed.

When mapping URL to objects within a file, one can again either
require that the full URL be mapped, like publisher does, or still
allow further path information for the nested handler to deal with.

Implementing code to go to file level only is pretty trivial, but
implementing traversing of objects etc becomes harder.

Thus, what are you actually after?

To get some ideas, you may want to have a look at what Vampire can do.
Through various means and at the option of the user, it can extend
through all levels.

You can find Vampire documentation at:

  http://www.dscpl.com.au/projects/vampire/articles.html

Graham


More information about the Mod_python mailing list