Reputation: 1597
I am getting myself up to speed with ArangoDB and Foxx, and so far the experience has been great! I have however one question:
For the Foxx router one can specify queryParams, for instance /graph/nodes?eyes=blue&hair=blond
.
What bothers me though is that I am forced (or at least, after several attempts I have such impression) that I have to hard code that I am expecting query params of eyes
and hair
.
Is this indeed true? And if yes, is there a work around? For me this is a bit strange within the context of nosql and being able to store documents with whatever attributes one wants in a collection.
I'd rather have that I can e.g. fetch the whole part of the URL after ?
, do a split("&")
on the string and catch whatever was part of the request.
Is there a way to do this within the Foxx framework?
Any help would be greatly appreciated!
Upvotes: 1
Views: 207
Reputation: 10902
I'm not sure why you think you are forced. The only distinction should be that query params specified as queryParam
will be validated (if a schema is provided) and documented.
You should be able to just use req.queryParams
to access additional query parameters:
router.get(function (req, res) {
res.json(req.queryParams);
})
.queryParam('documented', joi.number().optional());
GET /?documented=23 -> {"documented": 23}
GET /?more=42 -> {"more": "42"}
This assumes you are using ArangoDB 3.0 and not running a Foxx services written for 2.8 in legacy compatibility mode (i.e. you're using things called routers, not things called controllers).
Upvotes: 2
Reputation: 1597
Ok, I managed to find my solution myself, by using var query_params = req.originalUrl.split("?")[1];
. Then I get the string that I wanted with raw query parameters. From the manual:
originalUrl: string
Root-relative URL of the request, i.e. path followed by the raw query parameters, if any.
Upvotes: 0