Handling Edges
Examples will explain the REST API for manipulating edges of the graph module on the knows graph:
Create an edge
Creates an edge in an existing graph
POST /_api/gharial/{graph-name}/edge/{collection-name}
Creates a new edge in the collection. Within the body the has to contain a _from and _to value referencing to valid vertices in the graph. Furthermore the edge has to be valid in the definition of this edge collection.
Example:
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation <<EOF
{
"type" : "friend",
"_from" : "female/alice",
"_to" : "female/diana"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSdCO---
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_id" : "relation/7701",
"_key" : "7701",
"_rev" : "_VTxSdCO---"
},
"code" : 202
}
Path Parameters
- graph-name (required): The name of the graph.
- collection-name (required): The name of the edge collection the edge belongs to.
Query Parameters
- waitForSync (optional): Define if the request should wait until synced to disk.
- _from (required):
- _to (required):
Request Body (required)
The body has to be the JSON object to be stored.
Return Codes
- 201: Returned if the edge could be created.
- 202: Returned if the request was successful but waitForSync is false.
- 404: Returned if no graph with this name, no edge collection or no edge with this id could be found.
Examples
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation <<EOF
{
"type" : "friend",
"_from" : "female/alice",
"_to" : "female/diana"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSdCO---
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_id" : "relation/7701",
"_key" : "7701",
"_rev" : "_VTxSdCO---"
},
"code" : 202
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation <<EOF
{
"type" : "friend",
"_from" : "female/alice",
"_to" : "female/diana"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSdCO---
x-content-type-options: nosniff
Get an edge
fetch an edge
GET /_api/gharial/{graph-name}/edge/{collection-name}/{edge-key}
Gets an edge from the given collection.
Example:
shell> curl --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: _VTxSeBG--C
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_key" : "aliceAndBob",
"_id" : "relation/aliceAndBob",
"_from" : "female/alice",
"_to" : "male/bob",
"_rev" : "_VTxSeBG--C",
"type" : "married"
},
"code" : 200
}
Path Parameters
- graph-name (required): The name of the graph.
- collection-name (required): The name of the edge collection the edge belongs to.
- edge-key (required): The _key attribute of the vertex.
Header Parameters
- if-match (optional): If the "If-Match" header is given, then it must contain exactly one etag. The document is returned, if it has the same revision as the given etag. Otherwise a HTTP 412 is returned. As an alternative you can supply the etag in an attribute rev in the URL.
Return Codes
- 200: Returned if the edge could be found.
- 404: Returned if no graph with this name, no edge collection or no edge with this id could be found.
- 412: Returned if if-match header is given, but the documents revision is different.
Examples
shell> curl --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: _VTxSeBG--C
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_key" : "aliceAndBob",
"_id" : "relation/aliceAndBob",
"_from" : "female/alice",
"_to" : "male/bob",
"_rev" : "_VTxSeBG--C",
"type" : "married"
},
"code" : 200
}
shell> curl --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: _VTxSeBG--C
x-content-type-options: nosniff
Examples will explain the API on the social graph:
Modify an edge
modify an existing edge
PATCH /_api/gharial/{graph-name}/edge/{collection-name}/{edge-key}
Updates the data of the specific edge in the collection.
Example:
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob <<EOF
{
"since" : "01.01.2001"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSe4----
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_VTxSe4----",
"_oldRev" : "_VTxSe3y---"
},
"code" : 202
}
Path Parameters
- graph-name (required): The name of the graph.
- collection-name (required): The name of the edge collection the edge belongs to.
- edge-key (required): The _key attribute of the vertex.
Query Parameters
- waitForSync (optional): Define if the request should wait until synced to disk.
- keepNull (optional): Define if values set to null should be stored. By default the key is not removed from the document.
Request Body (required)
The body has to be a JSON object containing the attributes to be updated.
Return Codes
- 200: Returned if the edge could be updated.
- 202: Returned if the request was successful but waitForSync is false.
- 404: Returned if no graph with this name, no edge collection or no edge with this id could be found.
Examples
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob <<EOF
{
"since" : "01.01.2001"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSe4----
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_VTxSe4----",
"_oldRev" : "_VTxSe3y---"
},
"code" : 202
}
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob <<EOF
{
"since" : "01.01.2001"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSe4----
x-content-type-options: nosniff
Replace an edge
replace the content of an existing edge
PUT /_api/gharial/{graph-name}/edge/{collection-name}/{edge-key}
Replaces the data of an edge in the collection.
Example:
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob <<EOF
{
"type" : "divorced",
"_from" : "female/alice",
"_to" : "male/bob"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSf-O---
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_VTxSf-O---",
"_oldRev" : "_VTxSf-C--A"
},
"code" : 202
}
Path Parameters
- graph-name (required): The name of the graph.
- collection-name (required): The name of the edge collection the edge belongs to.
- edge-key (required): The _key attribute of the vertex.
Query Parameters
- waitForSync (optional): Define if the request should wait until synced to disk.
Header Parameters
- if-match (optional): If the "If-Match" header is given, then it must contain exactly one etag. The document is updated, if it has the same revision as the given etag. Otherwise a HTTP 412 is returned. As an alternative you can supply the etag in an attribute rev in the URL.
Request Body (required)
The body has to be the JSON object to be stored.
Return Codes
- 201: Returned if the request was successful but waitForSync is true.
- 202: Returned if the request was successful but waitForSync is false.
- 404: Returned if no graph with this name, no edge collection or no edge with this id could be found.
- 412: Returned if if-match header is given, but the documents revision is different.
Examples
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob <<EOF
{
"type" : "divorced",
"_from" : "female/alice",
"_to" : "male/bob"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSf-O---
x-content-type-options: nosniff
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_VTxSf-O---",
"_oldRev" : "_VTxSf-C--A"
},
"code" : 202
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob <<EOF
{
"type" : "divorced",
"_from" : "female/alice",
"_to" : "male/bob"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: _VTxSf-O---
x-content-type-options: nosniff
Remove an edge
removes an edge from graph
DELETE /_api/gharial/{graph-name}/edge/{collection-name}/{edge-key}
Removes an edge from the collection.
Example:
shell> curl -X DELETE --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
x-content-type-options: nosniff
{
"error" : false,
"removed" : true,
"code" : 202
}
Path Parameters
- graph-name (required): The name of the graph.
- collection-name (required): The name of the edge collection the edge belongs to.
- edge-key (required): The _key attribute of the vertex.
Query Parameters
- waitForSync (optional): Define if the request should wait until synced to disk.
Header Parameters
- if-match (optional): If the "If-Match" header is given, then it must contain exactly one etag. The document is updated, if it has the same revision as the given etag. Otherwise a HTTP 412 is returned. As an alternative you can supply the etag in an attribute rev in the URL.
Return Codes
- 200: Returned if the edge could be removed.
- 202: Returned if the request was successful but waitForSync is false.
- 404: Returned if no graph with this name, no edge collection or no edge with this id could be found.
- 412: Returned if if-match header is given, but the documents revision is different.
Examples
shell> curl -X DELETE --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
x-content-type-options: nosniff
{
"error" : false,
"removed" : true,
"code" : 202
}
shell> curl -X DELETE --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
x-content-type-options: nosniff