Handling Edges

Examples will explain the REST API for manipulating edges of the graph module on the knows graph:

Social Example 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
content-type: application/json; charset=utf-8
etag: _USnx87y---

{ 
  "error" : false, 
  "edge" : { 
    "_id" : "relation/7683", 
    "_key" : "7683", 
    "_rev" : "_USnx87y---" 
  }, 
  "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
content-type: application/json; charset=utf-8
etag: _USnx87y---

show response body

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: _USny-W2--B

{ 
  "error" : false, 
  "edge" : { 
    "_key" : "aliceAndBob", 
    "_id" : "relation/aliceAndBob", 
    "_from" : "female/alice", 
    "_to" : "male/bob", 
    "_rev" : "_USny-W2--B", 
    "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: _USny-W2--B

show response body

Examples will explain the API on the social graph:

Social Example 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
content-type: application/json; charset=utf-8
etag: _USny_bm---

{ 
  "error" : false, 
  "edge" : { 
    "_id" : "relation/aliceAndBob", 
    "_key" : "aliceAndBob", 
    "_rev" : "_USny_bm---", 
    "_oldRev" : "_USny_ba---" 
  }, 
  "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
content-type: application/json; charset=utf-8
etag: _USny_bm---

show response body

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
content-type: application/json; charset=utf-8
etag: _USny_jK---

{ 
  "error" : false, 
  "edge" : { 
    "_id" : "relation/aliceAndBob", 
    "_key" : "aliceAndBob", 
    "_rev" : "_USny_jK---", 
    "_oldRev" : "_USny_jC--B" 
  }, 
  "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
content-type: application/json; charset=utf-8
etag: _USny_jK---

show response body

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

show response body