Writing request handlers

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 ...

Get Building RESTful Python Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.