Skip to content

Rexster Implementation

spmallette edited this page Feb 26, 2013 · 11 revisions

<dependency>
   <groupId>com.tinkerpop.blueprints</groupId>
   <artifactId>blueprints-rexster-graph</artifactId>
   <version>??</version>
</dependency>

Rexster is a RESTful graph shell that exposes any Blueprints graph through a standalone HTTP server. RexsterGraph talks to a Rexster-exposed graph via the Rexster RESTful API. Thus, RexsterGraph can be used to communicate with a remote graph with complete HTTP-transparency to the user. RexsterGraph is composed of HTTP calls (through java.net.*) and JSON parsing.

Graph graph = new RexsterGraph("http://localhost:8182/graphs/tinkergraph");

NoteRexsterGraph is not meant for high-performing graph traversals. It is best suited for two things:

  1. Providing a convenient way to browse a remote graph with the Blueprints API.
  2. Exposing an easy way to issue requests to the Gremlin Extension Rexster via the execute method defined below.

Gremlin Scripts

It is possible to execute raw Gremlin scripts through RexsterGraph by using the execute method. The execute method will always return a JSONArray of results. Using the Gremlin REPL:

gremlin> g = new RexsterGraph("http://localhost:8182/graphs/tinkergraph")
==>rexstergraph[http://localhost:8182/graphs/tinkergraph[mocktinkertransactionalgraph[vertices:6 edges:6 directory:data/graph-example-1]]]
gremlin> g.execute("g.v(1)")                                             
==>[{"name":"marko","age":29,"_id":"1","_type":"vertex"}]

It is also possible to pass variables, as a second parameter, that will be bound to the script on execution.

gremlin> g.execute("g.v(x)",[x:1]) 
==>[{"name":"marko","age":29,"_id":"1","_type":"vertex"}]
gremlin> g.execute("g.v(x)",[x:1]).get(0).name
==>marko
gremlin> g.execute("g.v(x.toArray())",'{"x":[1,2]}')       
==>[{"name":"marko","age":29,"_id":"1","_type":"vertex"},{"name":"vadas","age":27,"_id":"2","_type":"vertex"}]
gremlin> import org.codehaus.jettison.json.JSONObject
...
gremlin> jsonParams = new JSONObject('{"x":[1,2]}')  
==>{"x":[1,2]}
gremlin> g.execute("g.v(x.toArray())",jsonParams)    
==>[{"name":"marko","age":29,"_id":"1","_type":"vertex"},{"name":"vadas","age":27,"_id":"2","_type":"vertex"}] 

Note that the Gremlin Extension must be configured in Rexster for this function to work.

Clone this wiki locally