Request objects

The names of some attributes of the request object have been adjusted to more closely align with those of the corresponding methods on the endpoint objects and established conventions in other JavaScript frameworks:

  • req.urlParameters is now called req.pathParams

  • req.parameters is now called req.queryParams

  • req.params() is now called req.param()

  • req.requestType is now called req.method

  • req.compatibility is now called req.arangoVersion

  • req.user is now called req.arangoUser

Some attributes have been removed or changed:

  • req.cookies has been removed entirely (use req.cookie(name))

  • req.requestBody has been removed entirely (see below)

  • req.suffix is now a string rather than an array

Additionally the req.server and req.client attributes are no longer available. The information is now exposed in a way that can (optionally) transparently handle proxy forwarding headers:

  • req.hostname defaults to req.server.address

  • req.port defaults to req.server.port

  • req.remoteAddress defaults to client.address

  • req.remotePort defaults to client.port

Finally, the req.cookie method now takes the signed options directly.

Old:

  1. const sid = req.cookie('sid', {
  2. signed: {
  3. secret: 'keyboardcat',
  4. algorithm: 'sha256'
  5. }
  6. });

New:

  1. const sid = req.cookie('sid', {
  2. secret: 'keyboardcat',
  3. algorithm: 'sha256'
  4. });

Request bodies

The req.body is no longer a method and no longer automatically parses JSON request bodies unless a request body was defined. The req.rawBody now corresponds to the req.rawBodyBuffer of ArangoDB 2.x and is also no longer a method.

Old:

  1. ctrl.post('/', function (req, res) {
  2. const data = req.body();
  3. // ...
  4. });

New:

  1. router.post('/', function (req, res) {
  2. const data = req.body;
  3. // ...
  4. })
  5. .body(['json']);

Or simply:

  1. const joi = require('joi');
  2. router.post('/', function (req, res) {
  3. const data = req.body;
  4. // ...
  5. })
  6. .body(joi.object().optional());

Multipart requests

The req.requestParts method has been removed entirely. If you need to accept multipart request bodies, you can simply define the request body using a multipart MIME type like multipart/form-data:

Old:

  1. ctrl.post('/', function (req, res) {
  2. const parts = req.requestParts();
  3. // ...
  4. });

New:

  1. router.post('/', function (req, res) {
  2. const parts = req.body;
  3. // ...
  4. })
  5. .body(['multipart/form-data']);