Nested routers

Instead of mounting routers where they are defined, routers can also be
exported from one module and imported in another. This allows you to
structure your routes by splitting them across multiple files:

// in your main fileconstusersRouter=require("./api/users");module.context.use("/users",usersRouter);// in api/users/index.jsconstcreateRouter=require("@arangodb/foxx/router");constusersRouter=createRouter();module.exports=usersRouter;usersRouter.get("/me",(req,res)=>{// this will be exposed as /users/me});

You can also mount routers inside of each other:

// in api/users/friends.jsconstcreateRouter=require("@arangodb/foxx/router");constfriendsRouter=createRouter();module.exports=friendsRouter;// in api/users/index.jsconstfriendsRouter=require("./friends");usersRouter.use("/friends",friendsRouter);

Note that you can also mount several routers with the same prefix
or even without a prefix:

adminRouter.use(usersAdminRouter);adminRouter.use(groupsAdminRouter);

Local middleware

Router-level middleware only applies to the router it is applied to and
is not shared between multiple routers mounted at the same prefix
(or without a prefix).

This can be especially useful when restricting access to
some routes but not others: