jsonify() function.
Basic JSON response
jsonify() accepts dicts, lists, strings, numbers, booleans, and None. It sets the Content-Type header to application/json automatically.
Returning SQLAlchemy models
SQLAlchemy models in BackAnt are@dataclass classes, which means they serialize to dicts automatically when passed to jsonify():
HTTP status codes
Pass the status code as the second return value:Error responses
Do not construct error responses manually in routes. RaiseAPIException from the service layer and the registered error handler in app.py converts it to JSON automatically:
APIException API.
Adding response headers
Returning empty responses
ForDELETE endpoints that return no body: