ArangoDB v2.8 reached End of Life (EOL) and is no longer supported.
This documentation is outdated. Please see the most recent version here: Try latest
Working with Edges using REST
This is documentation to ArangoDB’s REST interface for edges.
Read edge
reads a single edge
GET /_api/edge/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the edge collection.
-
document-key (required): The key of the edge document.
Header Parameters - If-None-Match (optional): If the “If-None-Match” header is given, then it must contain exactly one
etag. The edge is returned if it has a different revision than the
given etag. Otherwise an HTTP 304 is returned.
- If-Match (optional): If the “If-Match” header is given, then it must contain exactly one
etag. The edge is returned if it has the same revision ad the
given etag. Otherwise a HTTP 412 is returned. As an alternative
you can supply the etag in an attribute rev in the URL.
Returns the edge identified by document-handle. The returned edge contains a few special attributes: - _id contains the document handle
- _rev contains the revision
-
_from and to contain the document handles of the connected vertex documents
Return codes-
200: is returned if the edge was found
-
304: is returned if the “If-None-Match” header is given and the edge has the same version
-
404: is returned if the edge or collection was not found
-
412: is returned if a “If-Match” header or rev is given and the found document has a different version. The response will also contain the found document’s current revision in the _rev attribute. Additionally, the attributes _id and _key will be returned.
-
Read all edges from collection
reads all edges from collection
GET /_api/edge
Query Parameters
-
collection (required): The name of the collection.
Returns an array of all URIs for all edges from the collection identified by collection.
Return codes -
200: All went good.
-
404: The collection does not exist.
Create edge
creates an edge
POST /_api/edge
Query Parameters
- collection (required): Creates a new edge in the collection identified by collection name.
- createCollection (optional): If this parameter has a value of true or yes, then the collection is
created if it does not yet exist. Other values will be ignored so the
collection must be present for the operation to succeed.
Note: This flag is not supported in a cluster. Using it will result in an error. - waitForSync (optional): Wait until the edge document has been synced to disk.
- from (required): The document handle of the start point must be passed in from handle.
- to (required): The document handle of the end point must be passed in to handle.
Request Body (json)
A JSON representation of the edge document must be passed as the body of
the POST request. This JSON object may contain the edge’s document key in
the _key attribute if needed.
Creates a new edge document in the collection named collection. A JSON
representation of the document must be passed as the body of the POST
request.
The from and to handles are immutable once the edge has been created.
In all other respects the method works like POST /document.
Return codes
-
201: is returned if the edge was created successfully and waitForSync was true.
-
202: is returned if the edge was created successfully and waitForSync was false.
-
400: is returned if the body does not contain a valid JSON representation of an edge, or if the collection specified is not an edge collection. The response body contains an error document in this case.
-
404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.
Examples
Create an edge and read it back:
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/edge/?collection=edges&from=vertices/1&to=vertices/2 <<EOF
{
"name" : "Emil"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "740771969"
location: /_db/_system/_api/edge/edges/740771969
{
"error" : false,
"_id" : "edges/740771969",
"_rev" : "740771969",
"_key" : "740771969"
}
shell> curl --dump - http://localhost:8529/_api/edge/edges/740771969
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "740771969"
{
"name" : "Emil",
"_id" : "edges/740771969",
"_rev" : "740771969",
"_key" : "740771969",
"_from" : "vertices/1",
"_to" : "vertices/2"
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/edge/?collection=edges&from=vertices/1&to=vertices/2 <<EOF
{
"name" : "Emil"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "740771969"
location: /_db/_system/_api/edge/edges/740771969
Patches edge
updates an edge
PATCH /_api/edge/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the edge collection.
-
document-key (required): The key of the edge document.
Query Parameters - keepNull (optional): If the intention is to delete existing attributes with the patch command,
the URL query parameter keepNull can be used with a value of false.
This will modify the behavior of the patch command to remove any attributes
from the existing edge document that are contained in the patch document with an
attribute value of null.
- mergeObjects (optional): Controls whether objects (not arrays) will be merged if present in both the
existing and the patch edge. If set to false, the value in the
patch edge will overwrite the existing edge’s value. If set to
true, objects will be merged. The default is true.
- waitForSync (optional): Wait until edge document has been synced to disk.
- rev (optional): You can conditionally patch an edge document based on a target revision id by
using the rev query parameter.
-
policy (optional): To control the update behavior in case there is a revision mismatch, you can use the policy parameter.
Header Parameters - If-Match (optional): You can conditionally patch an edge document based on a target revision id by
using the if-match HTTP header.
Request Body (json)
A JSON representation of the edge update.
Partially updates the edge document identified by document-handle.
The body of the request must contain a JSON document with the attributes
to patch (the patch document). All attributes from the patch document will
be added to the existing edge document if they do not yet exist, and overwritten
in the existing edge document if they do exist there.
Setting an attribute value to null in the patch document will cause a
value of null be saved for the attribute by default.
Note: Internal attributes such as _key, _from and _to are immutable
once set and cannot be updated.
Optionally, the query parameter waitForSync can be used to force
synchronization of the edge document update operation to disk even in case
that the waitForSync flag had been disabled for the entire collection.
Thus, the waitForSync query parameter can be used to force synchronization
of just specific operations. To use this, set the waitForSync parameter
to true. If the waitForSync parameter is not specified or set to
false, then the collection’s default waitForSync behavior is
applied. The waitForSync query parameter cannot be used to disable
synchronization for collections that have a default waitForSync value
of true.
The body of the response contains a JSON object with the information about
the handle and the revision. The attribute _id contains the known
document-handle of the updated edge document, _key contains the key which
uniquely identifies a document in a given collection, and the attribute _rev
contains the new document revision.
If the edge document does not exist, then a HTTP 404 is returned and the
body of the response contains an error document.
You can conditionally update an edge document based on a target revision id by
using either the rev query parameter or the if-match HTTP header.
To control the update behavior in case there is a revision mismatch, you
can use the policy parameter. This is the same as when replacing
edge documents (see replacing documents for details).
Return codes
-
201: is returned if the document was patched successfully and waitForSync was true.
-
202: is returned if the document was patched successfully and waitForSync was false.
-
400: is returned if the body does not contain a valid JSON representation or when applied on an non-edge collection. The response body contains an error document in this case.
-
404: is returned if the collection or the edge document was not found
-
412: is returned if a “If-Match” header or rev is given and the found document has a different version. The response will also contain the found document’s current revision in the _rev attribute. Additionally, the attributes _id and _key will be returned.
replaces an edge
replaces an edge
PUT /_api/edge/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the edge collection.
-
document-key (required): The key of the edge document.
Query Parameters - waitForSync (optional): Wait until edge document has been synced to disk.
- rev (optional): You can conditionally replace an edge document based on a target revision id by
using the rev query parameter.
-
policy (optional): To control the update behavior in case there is a revision mismatch, you can use the policy parameter (see below).
Header Parameters - If-Match (optional): You can conditionally replace an edge document based on a target revision id by
using the if-match HTTP header.
Request Body (json)
A JSON representation of the new edge data.
Completely updates (i.e. replaces) the edge document identified by document-handle.
If the edge document exists and can be updated, then a HTTP 201 is returned
and the “ETag” header field contains the new revision of the edge document.
If the new edge document passed in the body of the request contains the
document-handle in the attribute _id and the revision in _rev,
these attributes will be ignored. Only the URI and the “ETag” header are
relevant in order to avoid confusion when using proxies.
Note: The attributes
_from and _to of an edge are immutable and cannot be updated either.
Optionally, the query parameter waitForSync can be used to force
synchronization of the edge document replacement operation to disk even in case
that the waitForSync flag had been disabled for the entire collection.
Thus, the waitForSync query parameter can be used to force synchronization
of just specific operations. To use this, set the waitForSync parameter
to true. If the waitForSync parameter is not specified or set to
false, then the collection’s default waitForSync behavior is
applied. The waitForSync query parameter cannot be used to disable
synchronization for collections that have a default waitForSync value
of true.
The body of the response contains a JSON object with the information about
the handle and the revision. The attribute _id contains the known
document-handle of the updated edge document, _key contains the key which
uniquely identifies a document in a given collection, and the attribute _rev
contains the new document revision.
If the edge document does not exist, then a HTTP 404 is returned and the
body of the response contains an error document.
There are two ways for specifying the targeted revision id for
conditional replacements (i.e. replacements that will only be executed if
the revision id found in the database matches the revision id specified
in the request):
- specifying the target revision in the rev URL query parameter
- specifying the target revision in the if-match HTTP header
Specifying a target revision is optional, however, if done, only one of the described mechanisms must be used (either the rev query parameter or the if-match HTTP header). Regardless which mechanism is used, the parameter needs to contain the target revision id as returned in the _rev attribute of an edge document or by an HTTP etag header.
For example, to conditionally replace an edge document based on a specific revision id, you can use the following request: - PUT /_api/document/collection-name/document-key?rev=etag
If a target revision id is provided in the request (e.g. via the etag value in the rev URL query parameter above), ArangoDB will check that the revision id of the edge document found in the database is equal to the target revision id provided in the request. If there is a mismatch between the revision id, then by default a HTTP 412 conflict is returned and no replacement is performed.
The conditional update behavior can be overridden with the policy URL query parameter: -
PUT /_api/document/collection-name/document-key?policy=policy
If policy is set to error, then the behavior is as before: replacements will fail if the revision id found in the database does not match the target revision id specified in the request.
If policy is set to last, then the replacement will succeed, even if the revision id found in the database does not match the target revision id specified in the request. You can use the last policy to force replacements.
Return codes-
201: is returned if the edge document was replaced successfully and waitForSync was true.
-
202: is returned if the edge document was replaced successfully and waitForSync was false.
-
400: is returned if the body does not contain a valid JSON representation of an edge document or if applied to a non-edge collection. The response body contains an error document in this case.
-
404: is returned if the collection or the edge document was not found
-
412: is returned if a “If-Match” header or rev is given and the found document has a different version. The response will also contain the found document’s current revision in the _rev attribute. Additionally, the attributes _id and _key will be returned.
-
Deletes edge
deletes an edge
DELETE /_api/edge/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the edge collection.
-
document-key (required): The key of the edge document.
Query Parameters - rev (optional): You can conditionally delete an edge document based on a target revision id by
using the rev query parameter.
- policy (optional): To control the update behavior in case there is a revision mismatch, you
can use the policy parameter. This is the same as when replacing edge
documents (see replacing edge documents for more details).
-
waitForSync (optional): Wait until edge document has been synced to disk.
Header Parameters -
If-Match (optional): You can conditionally delete an edge document based on a target revision id by using the if-match HTTP header.
The body of the response contains a JSON object with the information about the handle and the revision. The attribute _id contains the known document-handle of the deleted edge document, _key contains the key which uniquely identifies a document in a given collection, and the attribute _rev contains the new document revision.
If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.
Return codes -
200: is returned if the edge document was deleted successfully and waitForSync was true.
-
202: is returned if the edge document was deleted successfully and waitForSync was false.
-
404: is returned if the collection or the edge document was not found. The response body contains an error document in this case.
- 412: is returned if a “If-Match” header or rev is given and the found document has a different version. The response will also contain the found document’s current revision in the _rev attribute. Additionally, the attributes _id and _key will be returned.
Read edge header
reads a single edge head
HEAD /_api/edge/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the edge collection.
-
document-key (required): The key of the edge document.
Query Parameters -
rev (optional): You can conditionally fetch an edge document based on a target revision id by using the rev query parameter.
Header Parameters - If-None-Match (optional): If the “If-None-Match” header is given, then it must contain exactly one
etag. If the current document revision is different to the specified etag,
an HTTP 200 response is returned. If the current document revision is
identical to the specified etag, then an HTTP 304 is returned.
-
If-Match (optional): You can conditionally fetch an edge document based on a target revision id by using the if-match HTTP header.
Like GET, but only returns the header fields and not the body. You can use this call to get the current revision of an edge document or check if it was deleted.
Return codes -
200: is returned if the edge document was found
-
304: is returned if the “If-None-Match” header is given and the edge document has same version
-
404: is returned if the edge document or collection was not found
- 412: is returned if a “If-Match” header or rev is given and the found document has a different version. The response will also contain the found document’s current revision in the etag header.
Read in- or outbound edges
get edges
GET /_api/edges/{collection-id}
Path Parameters
-
collection-id (required): The id of the collection.
Query Parameters - vertex (required): The id of the start vertex.
-
direction (optional): Selects in or out direction for edges. If not set, any edges are returned.
Returns an array of edges starting or ending in the vertex identified by vertex-handle.
Return codes -
200: is returned if the edge collection was found and edges were retrieved.
-
400: is returned if the request contains invalid parameters.
- 404: is returned if the edge collection was not found.
Examples
Any direction
shell> curl --dump - http://localhost:8529/_api/edges/edges?vertex=vertices/1
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"edges" : [
{
"$label" : "v2 -> v1",
"_id" : "edges/6",
"_rev" : "744900737",
"_key" : "6",
"_from" : "vertices/2",
"_to" : "vertices/1"
},
{
"$label" : "v4 -> v1",
"_id" : "edges/7",
"_rev" : "745425025",
"_key" : "7",
"_from" : "vertices/4",
"_to" : "vertices/1"
},
{
"$label" : "v1 -> v3",
"_id" : "edges/5",
"_rev" : "744376449",
"_key" : "5",
"_from" : "vertices/1",
"_to" : "vertices/3"
}
],
"error" : false,
"code" : 200,
"stats" : {
"scannedIndex" : 3,
"filtered" : 0
}
}
shell> curl --dump - http://localhost:8529/_api/edges/edges?vertex=vertices/1
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
In edges
shell> curl --dump - http://localhost:8529/_api/edges/edges?vertex=vertices/1&direction=in
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"edges" : [
{
"$label" : "v2 -> v1",
"_id" : "edges/6",
"_rev" : "749619329",
"_key" : "6",
"_from" : "vertices/2",
"_to" : "vertices/1"
},
{
"$label" : "v4 -> v1",
"_id" : "edges/7",
"_rev" : "750143617",
"_key" : "7",
"_from" : "vertices/4",
"_to" : "vertices/1"
}
],
"error" : false,
"code" : 200,
"stats" : {
"scannedIndex" : 2,
"filtered" : 0
}
}
shell> curl --dump - http://localhost:8529/_api/edges/edges?vertex=vertices/1&direction=in
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Out edges
shell> curl --dump - http://localhost:8529/_api/edges/edges?vertex=vertices/1&direction=out
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"edges" : [
{
"$label" : "v1 -> v3",
"_id" : "edges/5",
"_rev" : "753813633",
"_key" : "5",
"_from" : "vertices/1",
"_to" : "vertices/3"
}
],
"error" : false,
"code" : 200,
"stats" : {
"scannedIndex" : 1,
"filtered" : 0
}
}
shell> curl --dump - http://localhost:8529/_api/edges/edges?vertex=vertices/1&direction=out
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8