Created
July 26, 2012 04:56
-
-
Save cjgiridhar/3180338 to your computer and use it in GitHub Desktop.
Tornado - Request Handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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