Skip to content

Instantly share code, notes, and snippets.

@an01f01
Last active July 8, 2022 11:53
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 an01f01/bd078a56a43e3a0bf87225596b382003 to your computer and use it in GitHub Desktop.
Save an01f01/bd078a56a43e3a0bf87225596b382003 to your computer and use it in GitHub Desktop.
class BooksHandler(BaseHandler):
"""
GET handler for fetching all books from the database
"""
@gen.coroutine
def get(self):
self.set_status(200)
self.write({'message': 'All books sorted by title', 'books': []})
self.finish()
"""
POST handler for adding a new book to the database
"""
@gen.coroutine
def post(self):
book_json = self.request.body.decode('utf-8')
book_json = tornado.escape.json_decode(book_json)
self.set_status(200)
self.write({'message': 'Book with id ' + params['id'], 'book': {}})
self.finish()
class BookHandler(BaseHandler):
"""
GET handler for fetching a specified book from the database
"""
@gen.coroutine
def get(self, **params):
self.set_status(200)
self.write({'message': 'Book with id' params['id'], 'book': {}})
self.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment