All of the response strategy classes return data. We need to decide what else should be returned. Here are the keys we return in the JSON response for the purposes of this discussion:
Key | Description |
status | HTTP status code |
data or error | Data if the operation is successful, and there is data to be returned Error if a problem was encountered |
link | The original page requested |
In the base class, we need to import the json module and define a few properties needed:
# web.responder.strategy.base
import json
class Base :
headers = []
data = {}
error = ''
status = 200
link = ''
Next, even though HTTP status codes are available in the http.HTTPStatus class (https://docs.python.org/3/library/http.html#http.HTTPStatus), the codes are configured as an enum, which proves awkward to use for our purposes. Accordingly, we define the HTTP status codes we use as a dictionary:
http_status = ...