Here is a more complete example. Basically, it shows how you can take
the "Hello World!" tutorial and make an httpclient.fetch() call to the
application and get its output:
import tornado.httpserver
import tornado.httpclient
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r"/", MainHandler),
])
def handle_request(response):
if response.error:
print "Error:", response.error
else:
print response.body
tornado.ioloop.IOLoop.instance().stop()
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
http_client = tornado.httpclient.AsyncHTTPClient()
http_client.fetch("
http://localhost:8888/", handle_request)
tornado.ioloop.IOLoop.instance().start()
I still need to come up with a working example that would make this
testable, like getting the output from the httpclient.fetch() and
comparing it to an expected string.