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.
free style json body
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
etag: _UoLi3Mi---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_id" : "relation/7684",
"_key" : "7684",
"_rev" : "_UoLi3Mi---"
},
"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):
Post Body
storeThisJsonObject (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
etag: _UoLi3Mi---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_id" : "relation/7684",
"_key" : "7684",
"_rev" : "_UoLi3Mi---"
},
"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
etag: _UoLi3Mi---
content-type: application/json; charset=utf-8
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
etag: _UoLi6yq---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_key" : "aliceAndBob",
"_id" : "relation/aliceAndBob",
"_from" : "female/alice",
"_to" : "male/bob",
"_rev" : "_UoLi6yq---",
"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
etag: _UoLi6yq---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_key" : "aliceAndBob",
"_id" : "relation/aliceAndBob",
"_from" : "female/alice",
"_to" : "male/bob",
"_rev" : "_UoLi6yq---",
"type" : "married"
},
"code" : 200
}
shell> curl --dump - http://localhost:8529/_api/gharial/social/edge/relation/aliceAndBob
HTTP/1.1 200 OK
etag: _UoLi6yq---
content-type: application/json; charset=utf-8
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.
free style json body
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
etag: _UoLj-Qe---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_UoLj-Qe---",
"_oldRev" : "_UoLj-QC---"
},
"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.
Post Body
updateAttributes (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
etag: _UoLj-Qe---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_UoLj-Qe---",
"_oldRev" : "_UoLj-QC---"
},
"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
etag: _UoLj-Qe---
content-type: application/json; charset=utf-8
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.
free style json body
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
etag: _UoLj-le---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_UoLj-le---",
"_oldRev" : "_UoLj-lC---"
},
"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.
Post Body
storeThisJsonObject (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
etag: _UoLj-le---
content-type: application/json; charset=utf-8
{
"error" : false,
"edge" : {
"_id" : "relation/aliceAndBob",
"_key" : "aliceAndBob",
"_rev" : "_UoLj-le---",
"_oldRev" : "_UoLj-lC---"
},
"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
etag: _UoLj-le---
content-type: application/json; charset=utf-8
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
{
"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
{
"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