I've made two distinct attempts at writing some wedges into CherryPy for
making object methods more REST-friendly. The first attempt uses a
decorator, while the second is a filter. Both seem to work, and both are
roughly equivalent in my mind. I'm a new TG/CP user, so please pardon me if
I've gone off and done or said something inappropriate.
The decorator version uses dispatch and introspection to locate the
appropriate method to call. The advantage with this approach is that it fits
into the CP request/response processing without too much fiddling, while the
disadvantage is the use of a second decorator.
The filter version uses the before_main hook to change the
request.object_path. From what I can tell, this looks like the correct
approach for this type of filter, but I could be wrong. The advantages of
the filter are better separation between client code and processing code and
a better fit into the CP framework. I can't think of a disadvantage of this
one, but you probably could.
If you have a moment, please try out the two attached modules and provide me
with any feedback. I'm uncertain what to do with the code... I'd like to see
one of them in the TG or CP distribution or on a wiki, but I don't have
permissions for any of that. Irrespective, I'll use probably end up using
the filter version in my own projects, so your input would be greatly
appreciated.
I wrote these against CP2 from svn, revision 929. Both make ad-hoc use of
http response codes, both need much solidification, documentation, and tests.
--
Troy Melhase, tr...@gci.net
--
Any sufficiently advanced technology is indistinguishable from Python.