HTTP Interface for Traversals

Traversals

ArangoDB's graph traversals are executed on the server. Traversals can be initiated by clients by sending the traversal description for execution to the server.

Traversals in ArangoDB are used to walk over a graph stored in one edge collection. It can easily be described which edges of the graph should be followed and which actions should be performed on each visited vertex. Furthermore the ordering of visiting the nodes can be specified, for instance depth-first or breadth-first search are offered.

Executing Traversals via HTTP

executes a traversal

execute a server-side traversal

POST /_api/traversal

Starts a traversal starting from a given vertex and following. edges contained in a given edgeCollection. The request must contain the following attributes.

A json post document with these Properties is required:

  • sort: body (JavaScript) code of a custom comparison function for the edges. The signature of this function is (l, r) -> integer (where l and r are edges) and must return -1 if l is smaller than, +1 if l is greater than, and 0 if l and r are equal. The reason for this is the following: The order of edges returned for a certain vertex is undefined. This is because there is no natural order of edges for a vertex with multiple connected edges. To explicitly define the order in which edges on the vertex are followed, you can specify an edge comparator function with this attribute. Note that the value here has to be a string to conform to the JSON standard, which in turn is parsed as function body on the server side. Furthermore note that this attribute is only used for the standard expanders. If you use your custom expander you have to do the sorting yourself within the expander code.
  • direction: direction for traversal
    • if set, must be either "outbound", "inbound", or "any"
    • if not set, the expander attribute must be specified
  • minDepth: ANDed with any existing filters): visits only nodes in at least the given depth
  • startVertex: id of the startVertex, e.g. "users/foo".
  • visitor: body (JavaScript) code of custom visitor function function signature: (config, result, vertex, path, connected) -> void The visitor function can do anything, but its return value is ignored. To populate a result, use the result variable by reference. Note that the connected argument is only populated when the order attribute is set to "preorder-expander".
  • itemOrder: item iteration order can be "forward" or "backward"
  • strategy: traversal strategy can be "depthfirst" or "breadthfirst"
  • filter: default is to include all nodes: body (JavaScript code) of custom filter function function signature: (config, vertex, path) -> mixed can return four different string values:
    • "exclude" -> this vertex will not be visited.
    • "prune" -> the edges of this vertex will not be followed.
    • "" or undefined -> visit the vertex and follow it's edges.
    • Array -> containing any combination of the above. If there is at least one "exclude" or "prune" respectivly is contained, it's effect will occur.
  • init: body (JavaScript) code of custom result initialization function function signature: (config, result) -> void initialize any values in result with what is required
  • maxIterations: Maximum number of iterations in each traversal. This number can be set to prevent endless loops in traversal of cyclic graphs. When a traversal performs as many iterations as the maxIterations value, the traversal will abort with an error. If maxIterations is not set, a server-defined value may be used.
  • maxDepth: ANDed with any existing filters visits only nodes in at most the given depth
  • uniqueness: specifies uniqueness for vertices and edges visited. If set, must be an object like this: "uniqueness": {"vertices": "none"|"global"|"path", "edges": "none"|"global"|"path"}
  • order: traversal order can be "preorder", "postorder" or "preorder-expander"
  • graphName: name of the graph that contains the edges. Either edgeCollection or graphName has to be given. In case both values are set the graphName is prefered.
  • expander: body (JavaScript) code of custom expander function must be set if direction attribute is not set function signature: (config, vertex, path) -> array expander must return an array of the connections for vertex each connection is an object with the attributes edge and vertex
  • edgeCollection: name of the collection that contains the edges.

If the Traversal is successfully executed HTTP 200 will be returned. Additionally the result object will be returned by the traversal.

For successful traversals, the returned JSON object has the following properties:

  • error: boolean flag to indicate if an error occurred (false in this case)

  • code: the HTTP status code

  • result: the return value of the traversal

If the traversal specification is either missing or malformed, the server will respond with HTTP 400.

The body of the response will then contain a JSON object with additional error details. The object has the following attributes:

  • error: boolean flag to indicate that an error occurred (true in this case)

  • code: the HTTP status code

  • errorNum: the server error number

  • errorMessage: a descriptive error message

Example:

In the following examples the underlying graph will contain five persons Alice, Bob, Charlie, Dave and Eve. We will have the following directed relations:

  • Alice knows Bob
  • Bob knows Charlie
  • Bob knows Dave
  • Eve knows Alice
  • Eve knows Bob

The starting vertex will always be Alice.

Follow only outbound edges

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONP3y---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONP32---", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONP32--_", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONP36---", 
          "name" : "Dave" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONP3y---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11882", 
              "_id" : "knows/11882", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONP4----" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONP3y---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONP32---", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11882", 
              "_id" : "knows/11882", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONP4----" 
            }, 
            { 
              "_key" : "11886", 
              "_id" : "knows/11886", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONP4---_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONP3y---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONP32---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONP32--_", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11882", 
              "_id" : "knows/11882", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONP4----" 
            }, 
            { 
              "_key" : "11889", 
              "_id" : "knows/11889", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONP4---A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONP3y---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONP32---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONP36---", 
              "name" : "Dave" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Follow only inbound edges

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "inbound" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONO3W---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONO3a--_", 
          "name" : "Eve" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONO3W---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11645", 
              "_id" : "knows/11645", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONO3e--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONO3W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONO3a--_", 
              "name" : "Eve" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Follow any direction of edges

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "uniqueness" : { 
    "vertices" : "none", 
    "edges" : "global" 
  } 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONNUi---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONNUm---", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONNUm--_", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONNUm--A", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONNUq---", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONNUi---", 
          "name" : "Alice" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNUi---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11224", 
              "_id" : "knows/11224", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNUu---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNUi---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNUm---", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11224", 
              "_id" : "knows/11224", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNUu---" 
            }, 
            { 
              "_key" : "11228", 
              "_id" : "knows/11228", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONNUy---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNUi---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNUm---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONNUm--_", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11224", 
              "_id" : "knows/11224", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNUu---" 
            }, 
            { 
              "_key" : "11231", 
              "_id" : "knows/11231", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONNUy--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNUi---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNUm---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONNUm--A", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11224", 
              "_id" : "knows/11224", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNUu---" 
            }, 
            { 
              "_key" : "11237", 
              "_id" : "knows/11237", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNU2--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNUi---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNUm---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNUq---", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11224", 
              "_id" : "knows/11224", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNUu---" 
            }, 
            { 
              "_key" : "11237", 
              "_id" : "knows/11237", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNU2--_" 
            }, 
            { 
              "_key" : "11234", 
              "_id" : "knows/11234", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONNU2---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNUi---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNUm---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNUq---", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNUi---", 
              "name" : "Alice" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Excluding Charlie and Bob

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "filter" : "if (vertex.name === \"Bob\" ||     vertex.name === \"Charlie\") {  return \"exclude\";}return;" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONOZe---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONOZi--_", 
          "name" : "Dave" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOZe---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11526", 
              "_id" : "knows/11526", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOZm---" 
            }, 
            { 
              "_key" : "11533", 
              "_id" : "knows/11533", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONOZm--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOZe---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONOZe--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONOZi--_", 
              "name" : "Dave" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Do not follow edges from Bob

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "filter" : "if (vertex.name === \"Bob\") {return \"prune\";}return;" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONOpm---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONOpq---", 
          "name" : "Bob" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOpm---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11583", 
              "_id" : "knows/11583", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOpu---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOpm---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONOpq---", 
              "name" : "Bob" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Visit only nodes in a depth of at least 2

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "minDepth" : 2 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONPpS--_", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONPpS--A", 
          "name" : "Dave" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ 
            { 
              "_key" : "11825", 
              "_id" : "knows/11825", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONPpW--_" 
            }, 
            { 
              "_key" : "11829", 
              "_id" : "knows/11829", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONPpa---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONPpO---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONPpS---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONPpS--_", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11825", 
              "_id" : "knows/11825", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONPpW--_" 
            }, 
            { 
              "_key" : "11832", 
              "_id" : "knows/11832", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONPpa--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONPpO---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONPpS---", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONPpS--A", 
              "name" : "Dave" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Visit only nodes in a depth of at most 1

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "maxDepth" : 1 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONPIa---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONPIa--_", 
          "name" : "Bob" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONPIa---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11688", 
              "_id" : "knows/11688", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONPIi---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONPIa---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONPIa--_", 
              "name" : "Bob" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Using a visitor function to return vertex ids only

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "visitor" : "result.visited.vertices.push(vertex._id);" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        "persons/alice", 
        "persons/bob", 
        "persons/charlie", 
        "persons/dave" 
      ], 
      "paths" : [ ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Count all visited nodes and return a list of nodes only

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "init" : "result.visited = 0; result.myVertices = [ ];", 
  "visitor" : "result.visited++; result.myVertices.push(vertex);" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : 4, 
    "myVertices" : [ 
      { 
        "_key" : "alice", 
        "_id" : "persons/alice", 
        "_rev" : "_UWONQry---", 
        "name" : "Alice" 
      }, 
      { 
        "_key" : "bob", 
        "_id" : "persons/bob", 
        "_rev" : "_UWONQry--_", 
        "name" : "Bob" 
      }, 
      { 
        "_key" : "charlie", 
        "_id" : "persons/charlie", 
        "_rev" : "_UWONQry--A", 
        "name" : "Charlie" 
      }, 
      { 
        "_key" : "dave", 
        "_id" : "persons/dave", 
        "_rev" : "_UWONQr2---", 
        "name" : "Dave" 
      } 
    ] 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Expand only inbound edges of Alice and outbound edges of Eve

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "expander" : "var connections = [ ];if (vertex.name === \"Alice\") {config.datasource.getInEdges(vertex).forEach(function (e) {connections.push({ vertex: require(\"internal\").db._document(e._from), edge: e});});}if (vertex.name === \"Eve\") {config.datasource.getOutEdges(vertex).forEach(function (e) {connections.push({vertex: require(\"internal\").db._document(e._to), edge: e});});}return connections;" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONRKm---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONRKu---", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONRKm--_", 
          "name" : "Bob" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONRKm---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "12089", 
              "_id" : "knows/12089", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONRKy--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONRKm---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONRKu---", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "12089", 
              "_id" : "knows/12089", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONRKy--A" 
            }, 
            { 
              "_key" : "12092", 
              "_id" : "knows/12092", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONRK2---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONRKm---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONRKu---", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONRKm--_", 
              "name" : "Bob" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Follow the depthfirst strategy

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "strategy" : "depthfirst" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONN2W---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONN2W--_", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONN2W--A", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONN2a---", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONN2a--_", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONN2W---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONN2a--_", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONN2W--_", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONN2W--A", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONN2a---", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONN2W---", 
          "name" : "Alice" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11375", 
              "_id" : "knows/11375", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2e---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11375", 
              "_id" : "knows/11375", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2e---" 
            }, 
            { 
              "_key" : "11379", 
              "_id" : "knows/11379", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONN2e--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONN2W--A", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11375", 
              "_id" : "knows/11375", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2e---" 
            }, 
            { 
              "_key" : "11382", 
              "_id" : "knows/11382", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONN2e--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONN2a---", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11375", 
              "_id" : "knows/11375", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2e---" 
            }, 
            { 
              "_key" : "11388", 
              "_id" : "knows/11388", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2i--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONN2a--_", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11375", 
              "_id" : "knows/11375", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2e---" 
            }, 
            { 
              "_key" : "11388", 
              "_id" : "knows/11388", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2i--_" 
            }, 
            { 
              "_key" : "11385", 
              "_id" : "knows/11385", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONN2i---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONN2a--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11385", 
              "_id" : "knows/11385", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONN2i---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONN2a--_", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11385", 
              "_id" : "knows/11385", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONN2i---" 
            }, 
            { 
              "_key" : "11388", 
              "_id" : "knows/11388", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2i--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONN2a--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11385", 
              "_id" : "knows/11385", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONN2i---" 
            }, 
            { 
              "_key" : "11388", 
              "_id" : "knows/11388", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2i--_" 
            }, 
            { 
              "_key" : "11379", 
              "_id" : "knows/11379", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONN2e--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONN2a--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONN2W--A", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11385", 
              "_id" : "knows/11385", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONN2i---" 
            }, 
            { 
              "_key" : "11388", 
              "_id" : "knows/11388", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2i--_" 
            }, 
            { 
              "_key" : "11382", 
              "_id" : "knows/11382", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONN2e--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONN2a--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONN2a---", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11385", 
              "_id" : "knows/11385", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONN2i---" 
            }, 
            { 
              "_key" : "11388", 
              "_id" : "knows/11388", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2i--_" 
            }, 
            { 
              "_key" : "11375", 
              "_id" : "knows/11375", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONN2e---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONN2a--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONN2W--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONN2W---", 
              "name" : "Alice" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Using postorder ordering

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "order" : "postorder" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONQI---_", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONQIC---", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONQH6---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONQIC--_", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONQI----", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONQI---_", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONQIC---", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONQH6---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONQI----", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONQIC--_", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONQH6---", 
          "name" : "Alice" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ 
            { 
              "_key" : "11939", 
              "_id" : "knows/11939", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIC--A" 
            }, 
            { 
              "_key" : "11943", 
              "_id" : "knows/11943", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONQIG---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONQI---_", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11939", 
              "_id" : "knows/11939", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIC--A" 
            }, 
            { 
              "_key" : "11946", 
              "_id" : "knows/11946", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONQIG--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONQIC---", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11939", 
              "_id" : "knows/11939", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIC--A" 
            }, 
            { 
              "_key" : "11952", 
              "_id" : "knows/11952", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIK--_" 
            }, 
            { 
              "_key" : "11949", 
              "_id" : "knows/11949", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONQIK---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONQIC--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11939", 
              "_id" : "knows/11939", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIC--A" 
            }, 
            { 
              "_key" : "11952", 
              "_id" : "knows/11952", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIK--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONQIC--_", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11939", 
              "_id" : "knows/11939", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIC--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11949", 
              "_id" : "knows/11949", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONQIK---" 
            }, 
            { 
              "_key" : "11952", 
              "_id" : "knows/11952", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIK--_" 
            }, 
            { 
              "_key" : "11943", 
              "_id" : "knows/11943", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONQIG---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONQIC--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONQI---_", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11949", 
              "_id" : "knows/11949", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONQIK---" 
            }, 
            { 
              "_key" : "11952", 
              "_id" : "knows/11952", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIK--_" 
            }, 
            { 
              "_key" : "11946", 
              "_id" : "knows/11946", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONQIG--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONQIC--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONQIC---", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11949", 
              "_id" : "knows/11949", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONQIK---" 
            }, 
            { 
              "_key" : "11952", 
              "_id" : "knows/11952", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIK--_" 
            }, 
            { 
              "_key" : "11939", 
              "_id" : "knows/11939", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIC--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONQIC--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11949", 
              "_id" : "knows/11949", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONQIK---" 
            }, 
            { 
              "_key" : "11952", 
              "_id" : "knows/11952", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONQIK--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONQIC--_", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONQI----", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11949", 
              "_id" : "knows/11949", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONQIK---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONQIC--_", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONQH6---", 
              "name" : "Alice" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Using backward item-ordering:

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "itemOrder" : "backward" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONNma---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONNme--A", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONNma--_", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONNma---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONNme--_", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONNme---", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONNma--_", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONNme--A", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONNma---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONNme--_", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONNme---", 
          "name" : "Charlie" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11302", 
              "_id" : "knows/11302", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONNmm---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNme--A", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11302", 
              "_id" : "knows/11302", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONNmm---" 
            }, 
            { 
              "_key" : "11305", 
              "_id" : "knows/11305", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmm--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNme--A", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11302", 
              "_id" : "knows/11302", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONNmm---" 
            }, 
            { 
              "_key" : "11305", 
              "_id" : "knows/11305", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmm--_" 
            }, 
            { 
              "_key" : "11292", 
              "_id" : "knows/11292", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmi---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNme--A", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11302", 
              "_id" : "knows/11302", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONNmm---" 
            }, 
            { 
              "_key" : "11305", 
              "_id" : "knows/11305", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmm--_" 
            }, 
            { 
              "_key" : "11299", 
              "_id" : "knows/11299", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONNmi--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNme--A", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONNme--_", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11302", 
              "_id" : "knows/11302", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONNmm---" 
            }, 
            { 
              "_key" : "11305", 
              "_id" : "knows/11305", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmm--_" 
            }, 
            { 
              "_key" : "11296", 
              "_id" : "knows/11296", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONNmi--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNme--A", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONNme---", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11292", 
              "_id" : "knows/11292", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmi---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11292", 
              "_id" : "knows/11292", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmi---" 
            }, 
            { 
              "_key" : "11305", 
              "_id" : "knows/11305", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmm--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNme--A", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11292", 
              "_id" : "knows/11292", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmi---" 
            }, 
            { 
              "_key" : "11305", 
              "_id" : "knows/11305", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmm--_" 
            }, 
            { 
              "_key" : "11302", 
              "_id" : "knows/11302", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONNmm---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONNme--A", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11292", 
              "_id" : "knows/11292", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmi---" 
            }, 
            { 
              "_key" : "11299", 
              "_id" : "knows/11299", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONNmi--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONNme--_", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11292", 
              "_id" : "knows/11292", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONNmi---" 
            }, 
            { 
              "_key" : "11296", 
              "_id" : "knows/11296", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONNmi--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONNma---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONNma--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONNme---", 
              "name" : "Charlie" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

Edges should only be included once globally, but nodes are included every time they are visited

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "uniqueness" : { 
    "vertices" : "none", 
    "edges" : "global" 
  } 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{ 
  "result" : { 
    "visited" : { 
      "vertices" : [ 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONOIy---", 
          "name" : "Alice" 
        }, 
        { 
          "_key" : "bob", 
          "_id" : "persons/bob", 
          "_rev" : "_UWONOIy--_", 
          "name" : "Bob" 
        }, 
        { 
          "_key" : "charlie", 
          "_id" : "persons/charlie", 
          "_rev" : "_UWONOI2---", 
          "name" : "Charlie" 
        }, 
        { 
          "_key" : "dave", 
          "_id" : "persons/dave", 
          "_rev" : "_UWONOI2--_", 
          "name" : "Dave" 
        }, 
        { 
          "_key" : "eve", 
          "_id" : "persons/eve", 
          "_rev" : "_UWONOI2--A", 
          "name" : "Eve" 
        }, 
        { 
          "_key" : "alice", 
          "_id" : "persons/alice", 
          "_rev" : "_UWONOIy---", 
          "name" : "Alice" 
        } 
      ], 
      "paths" : [ 
        { 
          "edges" : [ ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOIy---", 
              "name" : "Alice" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11458", 
              "_id" : "knows/11458", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOI2--B" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOIy---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONOIy--_", 
              "name" : "Bob" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11458", 
              "_id" : "knows/11458", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOI2--B" 
            }, 
            { 
              "_key" : "11462", 
              "_id" : "knows/11462", 
              "_from" : "persons/bob", 
              "_to" : "persons/charlie", 
              "_rev" : "_UWONOI6---" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOIy---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONOIy--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "charlie", 
              "_id" : "persons/charlie", 
              "_rev" : "_UWONOI2---", 
              "name" : "Charlie" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11458", 
              "_id" : "knows/11458", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOI2--B" 
            }, 
            { 
              "_key" : "11465", 
              "_id" : "knows/11465", 
              "_from" : "persons/bob", 
              "_to" : "persons/dave", 
              "_rev" : "_UWONOI6--_" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOIy---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONOIy--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "dave", 
              "_id" : "persons/dave", 
              "_rev" : "_UWONOI2--_", 
              "name" : "Dave" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11458", 
              "_id" : "knows/11458", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOI2--B" 
            }, 
            { 
              "_key" : "11471", 
              "_id" : "knows/11471", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOI6--B" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOIy---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONOIy--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONOI2--A", 
              "name" : "Eve" 
            } 
          ] 
        }, 
        { 
          "edges" : [ 
            { 
              "_key" : "11458", 
              "_id" : "knows/11458", 
              "_from" : "persons/alice", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOI2--B" 
            }, 
            { 
              "_key" : "11471", 
              "_id" : "knows/11471", 
              "_from" : "persons/eve", 
              "_to" : "persons/bob", 
              "_rev" : "_UWONOI6--B" 
            }, 
            { 
              "_key" : "11468", 
              "_id" : "knows/11468", 
              "_from" : "persons/eve", 
              "_to" : "persons/alice", 
              "_rev" : "_UWONOI6--A" 
            } 
          ], 
          "vertices" : [ 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOIy---", 
              "name" : "Alice" 
            }, 
            { 
              "_key" : "bob", 
              "_id" : "persons/bob", 
              "_rev" : "_UWONOIy--_", 
              "name" : "Bob" 
            }, 
            { 
              "_key" : "eve", 
              "_id" : "persons/eve", 
              "_rev" : "_UWONOI2--A", 
              "name" : "Eve" 
            }, 
            { 
              "_key" : "alice", 
              "_id" : "persons/alice", 
              "_rev" : "_UWONOIy---", 
              "name" : "Alice" 
            } 
          ] 
        } 
      ] 
    } 
  }, 
  "error" : false, 
  "code" : 200 
}

Example:

If the underlying graph is cyclic, maxIterations should be set

The underlying graph has two vertices Alice and Bob. With the directed edges:

  • Alice knows Bob
  • Bob knows Alice
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "uniqueness" : { 
    "vertices" : "none", 
    "edges" : "none" 
  }, 
  "maxIterations" : 5 
}
EOF

HTTP/1.1 500 Internal Server Error
content-type: application/json; charset=utf-8

{ 
  "error" : true, 
  "code" : 500, 
  "errorNum" : 1909, 
  "errorMessage" : "too many iterations - try increasing the value of 'maxIterations'" 
}

Return Codes

  • 200: If the traversal is fully executed HTTP 200 will be returned.
  • 400: If the traversal specification is either missing or malformed, the server will respond with HTTP 400.
  • 404: The server will responded with HTTP 404 if the specified edge collection does not exist, or the specified start vertex cannot be found.
  • 500: The server will responded with HTTP 500 when an error occurs inside the traversal or if a traversal performs more than maxIterations iterations.

Examples

In the following examples the underlying graph will contain five persons Alice, Bob, Charlie, Dave and Eve. We will have the following directed relations:

  • Alice knows Bob
  • Bob knows Charlie
  • Bob knows Dave
  • Eve knows Alice
  • Eve knows Bob The starting vertex will always be Alice. Follow only outbound edges
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Follow only inbound edges

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "inbound" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Follow any direction of edges

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "uniqueness" : { 
    "vertices" : "none", 
    "edges" : "global" 
  } 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Excluding Charlie and Bob

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "filter" : "if (vertex.name === \"Bob\" ||     vertex.name === \"Charlie\") {  return \"exclude\";}return;" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Do not follow edges from Bob

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "filter" : "if (vertex.name === \"Bob\") {return \"prune\";}return;" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Visit only nodes in a depth of at least 2

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "minDepth" : 2 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Visit only nodes in a depth of at most 1

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "maxDepth" : 1 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Using a visitor function to return vertex ids only

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "visitor" : "result.visited.vertices.push(vertex._id);" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Count all visited nodes and return a list of nodes only

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "outbound", 
  "init" : "result.visited = 0; result.myVertices = [ ];", 
  "visitor" : "result.visited++; result.myVertices.push(vertex);" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Expand only inbound edges of Alice and outbound edges of Eve

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "expander" : "var connections = [ ];if (vertex.name === \"Alice\") {config.datasource.getInEdges(vertex).forEach(function (e) {connections.push({ vertex: require(\"internal\").db._document(e._from), edge: e});});}if (vertex.name === \"Eve\") {config.datasource.getOutEdges(vertex).forEach(function (e) {connections.push({vertex: require(\"internal\").db._document(e._to), edge: e});});}return connections;" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Follow the depthfirst strategy

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "strategy" : "depthfirst" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Using postorder ordering

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "order" : "postorder" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Using backward item-ordering:

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "itemOrder" : "backward" 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

Edges should only be included once globally, but nodes are included every time they are visited

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "uniqueness" : { 
    "vertices" : "none", 
    "edges" : "global" 
  } 
}
EOF

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

show response body

If the underlying graph is cyclic, maxIterations should be set The underlying graph has two vertices Alice and Bob. With the directed edges:

  • Alice knows Bob
  • Bob knows Alice
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal <<EOF
{ 
  "startVertex" : "persons/alice", 
  "graphName" : "knows_graph", 
  "direction" : "any", 
  "uniqueness" : { 
    "vertices" : "none", 
    "edges" : "none" 
  }, 
  "maxIterations" : 5 
}
EOF

HTTP/1.1 500 Internal Server Error
content-type: application/json; charset=utf-8

show response body

All examples were using this graph:

Persons relation Example Graph