You can download this code by clicking the button below.
This code is now available for download.
This function creates a simple Tornado web server that fetches data from a specified URL and returns it.
Technology Stack : Tornado
Code Type : Web Server
Code Difficulty : Intermediate
import tornado.ioloop
import tornado.web
import tornado.httpclient
import random
def fetch_random_data(url):
class MainHandler(tornado.web.RequestHandler):
def get(self):
client = tornado.httpclient.HTTPClient()
response = client.fetch(url)
self.write(response.body)
self.finish()
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
])
tornado.ioloop.IOLoop.current().start()