ArangoDB graph operations via REST API

497 views Asked by At

Is it possible to use AQL query language via REST API to make graph queries?

Thanks.

2

There are 2 answers

0
stj On

Yes, HTTP Query cursor API is the right API to do this. It allows executing AQL queries via HTTP.

Example (with a non-graph query):

curl        \
  -X POST   \
  --dump -  \
  "http://localhost:8529/_db/_system/_api/cursor" \
  --data '{"query":"FOR u IN users RETURN u","count":true}'

You can put your AQL query string (using graph functions) into the query attribute of the request. Bind parameters are optional. If used, they can be put into the optional bindVars attribute of the request:

curl        \
  -X POST   \
  --dump -  \
  "http://localhost:8529/_db/_system/_api/cursor" \
  --data '{"query":"FOR u IN users FILTER u.name == @name RETURN u","bindVars":{"name":"foobar"}}'
0
Ralf Stein On

Great! But this AQL bellow works fine in the AQL editor, but not it the REST.

curl -X POST --dump - http://localhost:8529/_db/database/_api/cursor --data '{query:LET from = (FOR p IN products FILTER p.name == "p1" RETURN p._id) LET to=(FOR p IN products FILTER p.name == "p2" RETURN p._id) INSERT { _from: from[0], _to: to[0], type: "RELATED" } INTO productsedge}' HTTP/1.1 400 Bad Request Server: ArangoDB Connection: Keep-Alive Content-Type: application/json; charset=utf-8 Content-Length: 82 {"error":true,"errorMessage":"expecting attribute name","code":400,"errorNum":600}