Response objects

The response object has a lot of new methods in ArangoDB 3.0 but otherwise remains similar to the response object of previous versions:

The res.send method behaves very differently from how the method with the same name behaved in ArangoDB 2.x: the conversion now takes the response body definition of the route into account. There is a new method res.write that implements the old behavior.

Note that consecutive calls to res.write will append to the response body rather than replacing it like res.send.

The res.contentType property is also no longer available. If you want to set the MIME type of the response body to an explicit value you should set the content-type header instead:

Old:

  1. res.contentType = 'application/json';
  2. res.body = JSON.stringify(results);

New:

  1. res.set('content-type', 'application/json');
  2. res.body = JSON.stringify(results);

Or simply:

  1. // sets the content type to JSON
  2. // if it has not already been set
  3. res.json(results);

The res.cookie method now takes the signed options as part of the regular options object.

Old:

  1. res.cookie('sid', 'abcdef', {
  2. ttl: 60 * 60,
  3. signed: {
  4. secret: 'keyboardcat',
  5. algorithm: 'sha256'
  6. }
  7. });

New:

  1. res.cookie('sid', 'abcdef', {
  2. ttl: 60 * 60,
  3. secret: 'keyboardcat',
  4. algorithm: 'sha256'
  5. });