How to get an array as input body parameter in Foxx Application

75 views
Skip to first unread message

cagraw...@gmail.com

unread,
Apr 28, 2016, 1:31:58 AM4/28/16
to ArangoDB
Hi:
I am new to ArangoDB. I am using following controller in a Foxx App.
I am not able to get startPoints as an array. Can you provide right syntax and also, I am assuming format of data in the body should be:
["x", "y", "z"]
?

  controller.get("/executeNeighbors", function (req, res) {
    res.set("Content-Type", "text/plain; charset=utf-8");
    var mygraph = 'mygraph_c';
    var graph = graph_module._graph(mygraph);
    var rii = db._collection("rii_11");
    var start = req.param("startPoints"); // We load the body by the name defined later
    var query = aqlQuery`RETURN GRAPH_NEIGHBORS("mygraph_c", ${start}, {includeData: false, direction: "outbound", maxDepth: 10000000, minDepth: 1})`;
    var cursor = db._query(query);
    res.json(cursor.toArray());
  }).bodyParam("startPoints", joi.array());

Thanks,
CP

Wilfried Gösgens

unread,
Apr 28, 2016, 5:10:31 AM4/28/16
to ArangoDB
Hi,
I don't see where you defined joi or added values to it?
Do you use jslint to check for eventual typos?

Cheers,
Willi

Alan Plum

unread,
Apr 28, 2016, 5:52:53 AM4/28/16
to ArangoDB
Hi CP,

your code looks right as far as the body is concerned. Can you check what the actual value of `start` is by logging it to the console? Try `console.log(require('util').inspect(start))` for more detailed output.

If the array value is correct, can you also check the query using the web interface to see whether it behaves as expected using the input you're providing?

Cheers,

Alan

cagraw...@gmail.com

unread,
Apr 28, 2016, 2:02:26 PM4/28/16
to ArangoDB
I am attaching the entire app.js file. I took Hello-Foxx app and extended it.
Following is the response I get from the app for every type of input I have tried.
{
  "error": true,
  "code": 422,
  "errorNum": 422,
  "errorMessage": "Request body must be an array"
}
app.js

Alan Plum

unread,
Apr 29, 2016, 10:06:38 AM4/29/16
to ArangoDB
Hi again,

I just realized the route you're defining is a GET route (hence `controller.get`). The HTTP GET method does not permit a request body. You are probably trying to define a POST or PUT route (using `controller.post` or `controller.put`).

Cheers,

Alan

cagraw...@gmail.com

unread,
Apr 29, 2016, 2:38:48 PM4/29/16
to ArangoDB
First time I tried using put. Foxx application wouldn't compile (sorry, I don't have exact error handy now).
I have rewritten the application to save the input collection using bulk import and now sending start and end point of each input slice. Please see attached. This version seem to work fine.

On Wednesday, April 27, 2016 at 10:31:58 PM UTC-7, cagraw...@gmail.com wrote:
app.js
Reply all
Reply to author
Forward
0 new messages