The controller pattern
A correct BackAnt route function is always short:- Reads input from
requestif needed - Passes it to the service
- Returns
jsonify(response)
What does NOT belong in a route
Protected routes
Apply decorators directly to the route function. The@token_required decorator validates the Authorization header before the function runs:
Returning HTTP status codes
Pass the status code as the second argument tojsonify():
APIException from the service — the error handler in app.py converts it to JSON automatically. See Error Handling.
Auto-generated controller structure
Whenant generate route orders runs, the generated route file looks like:
ant generate subroute call appends a new endpoint function to this file.