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 calledreq.pathParams
-
req.parameters
is now calledreq.queryParams
-
req.params()
is now calledreq.param()
-
req.requestType
is now calledreq.method
-
req.compatibility
is now calledreq.arangoVersion
-
req.user
is now calledreq.arangoUser
Some attributes have been removed or changed:
-
req.cookies
has been removed entirely (usereq.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 toreq.server.address
-
req.port
defaults toreq.server.port
-
req.remoteAddress
defaults toclient.address
-
req.remotePort
defaults toclient.port
Finally, the req.cookie
method now takes the signed
options directly.
Old:
const sid = req.cookie('sid', {
signed: {
secret: 'keyboardcat',
algorithm: 'sha256'
}
});
New:
const sid = req.cookie('sid', {
secret: 'keyboardcat',
algorithm: 'sha256'
});
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:
ctrl.post('/', function (req, res) {
const data = req.body();
// ...
});
New:
router.post('/', function (req, res) {
const data = req.body;
// ...
})
.body(['json']);
Or simply:
const joi = require('joi');
router.post('/', function (req, res) {
const data = req.body;
// ...
})
.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:
ctrl.post('/', function (req, res) {
const parts = req.requestParts();
// ...
});
New:
router.post('/', function (req, res) {
const parts = req.body;
// ...
})
.body(['multipart/form-data']);