Neither Flask nor Flask-RESTful includes the declaration of variables for the different HTTP status codes. We don't want to return numbers as status codes. We want our code to be easy to read and understand, and therefore, we will use descriptive HTTP status codes. We will borrow the code that declares useful functions and variables related to HTTP status codes from the status.py
file included in Django REST Framework, that is, the framework we have been using in the preceding chapters.
First, create a folder named api
within the root folder for the recently created virtual environment, and then create a new status.py
file within the api
folder. The following lines show the code that declares functions and variables with descriptive HTTP status codes in the api/models.py
file borrowed from the rest_framework.status
module. We don't want to reinvent the wheel, and the module provides everything we need to work with HTTP status codes in our Flask-based...