Created
October 12, 2015 18:13
-
-
Save ramhiser/745db53bc54340343d56 to your computer and use it in GitHub Desktop.
Simple Tornado server example
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 tornado | |
import tornado.ioloop | |
import tornado.web | |
from tornado.httpclient import AsyncHTTPClient | |
class MainHandler(tornado.web.RequestHandler): | |
@gen.coroutine | |
def get(self): | |
http = AsyncHTTPClient(method="POST") | |
print http | |
response = yield http.fetch("http://google.com") | |
print response | |
self.write("Num Bytes Fetched from Google: " + str(len(response.body))) | |
def make_app(): | |
return tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
app = make_app() | |
app.listen(8888) | |
tornado.ioloop.IOLoop.current().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment