Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created July 26, 2012 04:56
Show Gist options
  • Save cjgiridhar/3180338 to your computer and use it in GitHub Desktop.
Save cjgiridhar/3180338 to your computer and use it in GitHub Desktop.
Tornado - Request Handling
import httplib2
h = httplib2.Http(".cache")
resp, content = h.request("http://127.0.0.1:8888/user/john/designation/doctor", "GET")
print "Reponse:", resp, "\nContent:", content
mport tornado.ioloop
import tornado.web
class Hello(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class User(tornado.web.RequestHandler):
def get(self, username,designation):
self.get_arguments(username, strip=True)
self.get_arguments(designation,strip=True)
self.write("Wow " + username + " you're a " + designation)
application = tornado.web.Application([
(r"/", Hello),
(r"/user/(.*)/designation/(.*)", User),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment