The request context

When defining a route on a controller the controller would return an object called request context. Routers return a similar object called endpoint. Routers also return endpoints when mounting child routers or middleware, as does the use method of the service context.

The main differences between the new endpoints and the objects returned by controllers in previous versions of ArangoDB are:

  • bodyParam is now simply called body; it is no longer neccessary or possible to give the body a name and the request body will not show up in the request parameters. It’s also possible to specify a MIME type

  • body, queryParam and pathParam now take position arguments instead of an object. For specifics see the endpoint documentation.

  • notes is now called description and takes a single string argument.

  • onlyIf and onlyIfAuthenticated are no longer available; they can be emulated with middleware if necessary:

Old:

  1. ctrl.get(/* ... */)
  2. .onlyIf(function (req) {
  3. if (!req.user) {
  4. throw new Error('Not authenticated!');
  5. }
  6. });

New:

  1. router.use(function (req, res, next) {
  2. if (!req.arangoUser) {
  3. res.throw(403, 'Not authenticated!');
  4. }
  5. next();
  6. });
  7. router.get(/* ... */);