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:
'use strict';
const createRouter = require('org/arangodb/foxx/router');
const router = createRouter();
// If you are importing this file from your entry file ("main"):
module.exports = router;
// ...
});
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
ifnum
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
andactivateSessions
methods. Instead you should use the session middleware (see the section on sessions below).There is no
del
alias for thedelete
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.