[mod_python] providing REST style interfaces

David Bear David.Bear at asu.edu
Fri Jan 4 13:11:19 EST 2008


On Fri, Jan 04, 2008 at 04:32:14AM -0500, Deron Meranda wrote:
> 
> def handler( req ):
>     # Extract the resource name (the CCCC portion of the URL):
>     uripath = [p for p in req.uri.split('/') if p]
>     if len(uripath) != 2 or uripath[0] != 'descriptor':
>         raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
>     resource_name = uripath[-1]
> 
>     # Now figure out what we want to do to the resource
>     if req.method == 'GET':
>         try:
>             content = resource_database[resource_name]
>         except KeyError:
>             raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
>         req.content_type = 'application/octet-stream'
>         req.write( content )
>     elif req.method == 'PUT':
>          content = req.read()
>          resource_database[resource_name] = content
>     elif req.method == 'DELETE':
>          del resource_database[resource_name]
>     else:
>         raise apache.SERVER_RETURN, apache.HTTP_METHOD_NOT_ALLOWED
> 
>     return apache.OK
> 

WOW. Thanks. This is a great descriptions on REST and the most
understandable I've looked at. The code is the teacher.


-- 
David Bear
phone: 	602-496-0424
fax: 	602-496-0955
College of Public Programs/ASU
University Center Rm 622
411 N Central
Phoenix, AZ 85007-0685
 "Beware the IP portfolio, everyone will be suspect of trespassing"


More information about the Mod_python mailing list