Skip to main content
All BackAnt routes return JSON using Flask’s 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():
For lists of models:

HTTP status codes

Pass the status code as the second return value:

Error responses

Do not construct error responses manually in routes. Raise APIException from the service layer and the registered error handler in app.py converts it to JSON automatically:
See Error Handling for the full APIException API.

Adding response headers

Returning empty responses

For DELETE endpoints that return no body:
Or with a confirmation message: