How to do python and RESTful

Adonis Vargas adonisv at REMOVETHISearthlink.net
Wed Sep 5 21:21:57 EDT 2007


MarkyMarc wrote:
> Hi all,
> 
> I want to make a web service application in python and keywords are
> RESTful, python and nice urls(urls mapped to python objects).
> 
> I don't want a big framework but a nice small one, that can just do
> the things I want.
> 
> I have be looking at quixote, but is this uptodate? "plain"
> mod_python, can this make url to http put,get,delete and post?
> 
> Can some one here point me some where I can read about python and
> RESTful or have some experiences with other?
> 
> Any help is apricieted.
> 
> Regards Marc
> 

Here is a crude version, if you check out CherryPy there exists a 
RESTful module for it floating around. Plus you will get the power or 
CherryPy for your apps. I do not have the urls offhand but google should 
yeild exactly what you need.

import BaseHTTPServer

class REST(BaseHTTPServer.BaseHTTPRequestHandler):

     """
     You can implement and do_* method you want
     """

     def do_GET(self):
         self.wfile.write("get")

     def do_POST(self):
         self.wfile.write("post")

     def do_PUT(self):
         self.wfile.write("put")

     def do_DELETE(self):
         self.wfile.write("delete")

def main(server_class=BaseHTTPServer.HTTPServer, handler_class=REST):
     server_address = ('', 8000)
     httpd = server_class(server_address, handler_class)
     httpd.serve_forever()

if __name__ == '__main__':
     main()

Not fully tested but should get on your feet.

Hope this helps.

Adonis Vargas



More information about the Python-list mailing list