A very similar process occurs within the strategy class representing the JSON:API format:
# web.responder.strategy.json_api
from web.responder.strategy.base import Base
class JsonApiStrategy(Base) :
content_type = 'application/vnd.api+json'
Again, if self.error is set, an error key contains the error message. If there is data in self.data, it is wrapped in the appropriate syntax for this format. The base class buildOutput() method is called to assemble the final response:
def render(self) :
payload = dict({'links':{'self':self.link }})
if self.error :
payload['error'] = self.error
if self.data :
count = 1
data = {}
for key, value in self.data.items() :
if 'category' in value :
prodType = value['category']
else :
prodType = 'N/A'
...