Response JSON

class routing.ResponseJSON[source]

Class managing a JSON-encoded response (for an API request).

HEADER_CONTENT_TYPE = {'Content-Type': 'application/json'}
STATUS_ERROR = 'error'
STATUS_FAIL = 'fail'
STATUS_SUCCESS = 'success'
static get_json_data(status='error', title=False, description=False, data=False)[source]

Build a dictionary containing all the arguments’ data, and encode it as JSON.

Parameters:
  • status – A string with the status of the response (please, use the STATUS_* constants defined in this class!)
  • title – A string with summary information about the response (in case of error: the name of the Exception)
  • description – A string with complete information about the response (in case of error: the complete error message)
  • data – A dictionary with the actual payload of the JSON response
Returns:

A JSON-encoded dictionary containing all the data from the arguments passed to this function