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.

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
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47Mfu--_

{ 
  "error" : false, 
  "edge" : { 
    "_id" : "relation/7889", 
    "_key" : "7889", 
    "_rev" : "_WQ47Mfu--_" 
  }, 
  "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
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47Mfu--_

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/8613

HTTP/1.1 200 OK
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47QdC--D

{ 
  "error" : false, 
  "edge" : { 
    "_key" : "8613", 
    "_id" : "relation/8613", 
    "_from" : "female/alice", 
    "_to" : "male/bob", 
    "_rev" : "_WQ47QdC--D", 
    "type" : "married", 
    "vertex" : "alice" 
  }, 
  "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/8613

HTTP/1.1 200 OK
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47QdC--D

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.

Example:

shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/9263 <<EOF
{ 
  "since" : "01.01.2001" 
}
EOF

HTTP/1.1 202 Accepted
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47Sgy--_

{ 
  "error" : false, 
  "edge" : { 
    "_id" : "relation/9263", 
    "_key" : "9263", 
    "_rev" : "_WQ47Sgy--_", 
    "_oldRev" : "_WQ47Sgm--H" 
  }, 
  "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/9263 <<EOF
{ 
  "since" : "01.01.2001" 
}
EOF

HTTP/1.1 202 Accepted
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47Sgy--_

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.

Example:

shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/gharial/social/edge/relation/9340 <<EOF
{ 
  "type" : "divorced", 
  "_from" : "female/alice", 
  "_to" : "male/bob" 
}
EOF

HTTP/1.1 202 Accepted
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47SvK--_

{ 
  "error" : false, 
  "edge" : { 
    "_id" : "relation/9340", 
    "_key" : "9340", 
    "_rev" : "_WQ47SvK--_", 
    "_oldRev" : "_WQ47SvC--H" 
  }, 
  "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/9340 <<EOF
{ 
  "type" : "divorced", 
  "_from" : "female/alice", 
  "_to" : "male/bob" 
}
EOF

HTTP/1.1 202 Accepted
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: _WQ47SvK--_

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/8310

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/8310

HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
x-content-type-options: nosniff

show response body