Skip to main content
In BackAnt, the route layer is the controller. Its only job is to receive an HTTP request, call the service, and return a JSON response. All logic lives in the service.

The controller pattern

A correct BackAnt route function is always short:
The route:
  1. Reads input from request if needed
  2. Passes it to the service
  3. 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:
See Authentication for decorator details.

Returning HTTP status codes

Pass the status code as the second argument to jsonify():
For error responses, raise APIException from the service — the error handler in app.py converts it to JSON automatically. See Error Handling.

Auto-generated controller structure

When ant generate route orders runs, the generated route file looks like:
Every subsequent ant generate subroute call appends a new endpoint function to this file.