This is an introduction to ArangoDB's REST interface for edges.
AvocacadoDB offers also some graph functionality. A graph consists of nodes, edges and properties. ArangoDB stores the information how the nodes relate to each other aside from the properties.
So a graph data model always consists of two collections: the relations between the nodes in the graphs are stored in an "edges collection", the nodes in the graph are stored in documents in regular collections.
Example:
_from
and _to
property_from
is the document handle of the linked vertex (incoming relation), _to
is the document handle of the linked vertex (outgoing relation).
Edge: Edges in ArangoDB are special documents. In addition to the internal attributes _id
and _rev
, they have two attributes _form
and _to
, which contain document handles namely the start-point and the end-point of the edge.
All documents in ArangoDB have a document handle. This handle uniquely defines a document and is managed by ArangoDB. All documents are found under the URI
http://server:port/_api/document/document-handle
For edges you can use the special address
http://server:port/_api/edge/document-handle
For example: Assume that the document handle, which is stored in the _id
field of the edge, is 7254820/362549736
, then the URL of that edge is:
http://localhost:8529/_api/edge/7254820/362549736
GET /_api/edge/document-handle
See REST Interface for Documents for details.
POST /_api/edge?collection=collection-identifier&from=from-handle&to=to-handle
Creates a new edge in the collection identified by the collection-identifier. A JSON representation of the document must be passed as the body of the POST request. The object handle of the start point must be passed in from-handle. The object handle of the end point must be passed in to-handle.
In all other respects the method works like POST /document
, see REST Interface for Documents for details.
If you request such an edge, the returned document will also contain the attributes _from
and _to
.
Examples
Create an edge:
> curl --data @- -X POST --dump - http://localhost:8529/_api/edge?collection=7848004&from=7848004/9289796&to=7848004/9355332 { "e" : 1 } HTTP/1.1 201 Created content-type: application/json; charset=utf-8 location: /_api/document/7848004/9683012 etag: "9683012" { "_rev": 9683012, "_id": "7848004/9683012", "error": false }
Read an edge:
> curl -X GET --dump - http://localhost:8529/_api/edge/7848004/9683012 HTTP/1.1 200 OK content-type: application/json; charset=utf-8 etag: "9683012" { "_from": "7848004/9289796", "_rev": 9683012, "_to": "7848004/9355332", "_id": "7848004/9683012", "e": 1 }
PUT /_api/edge/document-handle
See REST Interface for Documents for details.
DELETE /_api/edge/document-handle
See REST Interface for Documents for details.
HEAD /_api/edge/document-handle
See REST Interface for Documents for details.
GET /_api/edges/collection-identifier?vertex=vertex-handle&direction=any
Returns the list of edges starting or ending in the vertex identified by vertex-handle.
GET /_api/edges/collection-identifier?vertex=vertex-handle&direction=in
Returns the list of edges ending in the vertex identified by vertex-handle.
GET /_api/edges/collection-identifier?vertex=vertex-handle&direction=out
Returns the list of edges starting in the vertex identified by vertex-handle.
Examples
Any direction
> curl -X GET --dump - http://localhost:8529/_api/edges/17501660?vertex=17501660/18419164 HTTP/1.1 200 OK content-type: application/json { "edges": [ { "_from": "17501660/18419164", "_rev": 19140060, "_to": "17501660/19008988", "_id": "17501660/19140060" }, { "_from": "17501660/18419164", "_rev": 19336668, "_to": "17501660/19008988", "_id": "17501660/19336668", "e": 1 }, { "_from": "17501660/19008988", "_rev": 19402204, "_to": "17501660/18419164", "_id": "17501660/19402204", "e": 2 } ], "code": 200, "error": false }
In edges
> curl -X GET --dump - http://localhost:8529/_api/edges/17501660?vertex=17501660/18419164&direction=in HTTP/1.1 200 OK content-type: application/json { "edges": [ { "_from": "17501660/19008988", "_rev": 19402204, "_to": "17501660/18419164", "_id": "17501660/19402204", "e": 2 } ], "code": 200, "error": false }
Out edges
> curl -X GET --dump - http://localhost:8529/_api/edges/17501660?vertex=17501660/18419164&direction=out HTTP/1.1 200 OK content-type: application/json { "edges": [ { "_from": "17501660/18419164", "_rev": 19336668, "_to": "17501660/19008988", "_id": "17501660/19336668", "e": 1 }, { "_from": "17501660/18419164", "_rev": 19140060, "_to": "17501660/19008988", "_id": "17501660/19140060" } ], "code": 200, "error": false }