Skip to content

Instantly share code, notes, and snippets.

@RichardBray
Created October 5, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBray/d93b557c569fc3e9fe7f4746ad891db7 to your computer and use it in GitHub Desktop.
Save RichardBray/d93b557c569fc3e9fe7f4746ad891db7 to your computer and use it in GitHub Desktop.
from tornado.web import Application, RequestHandler
from tornado.ioloop import IOLoop
items = []
class TodoItems(RequestHandler):
def get(self):
self.write({'items': items})
class TodoItem(RequestHandler):
def post(self):
items.append(self.request.body)
self.write({'message': self.request.body})
def make_app():
urls = [
("/", TodoItems),
("/api/item/", TodoItem)
]
return Application(urls, debug=True)
if __name__ == '__main__':
app = make_app()
app.listen(3000)
IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment