Controllers vs routers

    Controllers were automatically mounted when the file defining them was executed. Routers need to be explicitly mounted using the method. Routers can also be exported, imported and even nested. This makes it easier to split up complex routing trees across multiple files.

    Old:

    New:

    1. 'use strict';
    2. const createRouter = require('org/arangodb/foxx/router');
    3. const router = createRouter();
    4. // If you are importing this file from your entry file ("main"):
    5. module.exports = router;
    6. // ...
    7. });
    • When specifying path parameters with schemas Foxx will now ignore the route if the schema does not match (i.e. /hello/foxx will no longer match /hello/:num if num specifies a schema that doesn’t match the value "foxx"). With controllers this could previously result in users seeing a 400 (bad request) error when they should instead be served a 404 (not found) response.

    • Foxx will no longer parse your JSDoc comments to generate route documentation (use the and description methods of the endpoint instead).

    • There is no router equivalent for the activateAuthentication and activateSessions methods. Instead you should use the session middleware (see the section on sessions below).

    • There is no del alias for the delete method on routers. It has always been safe to use keywords as method names in Foxx, so the use of this alias was already discouraged before.

    • The allRoutes proxy is no lot available on routers but can easily be replaced with middleware or child routers.