diff --git a/Documentation/Books/Manual/Foxx/Migrating2x.mdpp b/Documentation/Books/Manual/Foxx/Migrating2x.mdpp index 60184189c5..ea07db9a25 100644 --- a/Documentation/Books/Manual/Foxx/Migrating2x.mdpp +++ b/Documentation/Books/Manual/Foxx/Migrating2x.mdpp @@ -357,10 +357,35 @@ afterRemove(doc); !SECTION Controllers vs routers -Foxx Controllers have been replaced with [Routers](Router/README.md). This is more than a cosmetic change as there are significant differences in behaviour: +Foxx Controllers have been replaced with [routers](Router/README.md). This is more than a cosmetic change as there are significant differences in behaviour: Controllers were automatically mounted when the file defining them was executed. Routers need to be explicitly mounted using the `module.context.use` method. Routers can also be exported, imported and even nested. This makes it easier to split up complex routing trees across multiple files. +Old: + +```js +'use strict'; +const Foxx = require('org/arangodb/foxx'); +const ctrl = new Foxx.Controller(applicationContext); + +ctrl.get('/hello', function (req, res) { + // ... +}); +``` + +New: + +```js +'use strict'; +const createRouter = require('org/arangodb/foxx/router'); +const router = createRouter(); +module.context.use(router); + +router.get('/hello', function (req, res) { + // ... +}); +``` + Some general changes in behaviour that might trip you up: * 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.