The main building blocks for a RESTful API in tornado are subclasses of the tornado.web.RequestHandler
class, that is, the base class for HTTP request handlers in Tornado. We just need to create a subclass of this class and declare the methods for each supported HTTP verb. We have to override the methods to handle HTTP requests. Then, we have to map the URL patterns to each subclass of tornado.web.RequestHandler
in the tornado.web.Application
instance that represents the Tornado Web application.
First, we will create a HexacopterHandler
class that we will use to handle requests for the hexacopter resource. Create a new api.py
file. The following lines show all the necessary imports for the classes that we will create and the code that declares the HexacopterHandler
class in the drone.py
file. Enter the next lines in the new api.py
file. The code file for the sample is included in the restful_python_chapter_09_01
folder:
import status from datetime import date from...