Last active
May 4, 2016 20:20
-
-
Save stalkerg/feda19c17c0499baa52d68dc6dd1fc4c to your computer and use it in GitHub Desktop.
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.ioloop | |
import tornado.web | |
import json | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self, type_r=None): | |
format_answer = self.get_argument("format", "json") | |
# bla bla request to postgres | |
if format_answer == "sql": | |
self.write(my_sql_answer) | |
else: | |
self.set_header('Content-Type', 'application/json') | |
self.write(json.dumps(my_json_objetc_asnwer) | |
def make_app(): | |
return tornado.web.Application([ | |
(r"/gen1", MainHandler, "gen_1"), | |
(r"/gen2", MainHandler, "gen_2"), | |
(r"/gen3/(.*)", MainHandler) | |
]) | |
if __name__ == "__main__": | |
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