7

If I run neo4j in server mode so it is accessible using the REST API, can I access the same neo4j instance with EmbeddedGraphDatabase-class?

I am thinking of a production setup where a Java-app using EmbeddedGraphDatabase is driving the logic, but other clients might navigate the data with REST in readonly mode.

1 Answer 1

7

What you are describing is a server plugin or extension. That way you expose your database via the REST API but at the same time you can access the embedded graph db hihgly performant from your custom plugin/extension code.

In your custom code you can get a GraphDatabaseService injected on which you operate.

You deploy your custom extensions as jars with your neo4j-server and have client code operate over a domain oriented restful API with it.

// extension sample
@Path( "/helloworld" )
public class HelloWorldResource {

private final GraphDatabaseService database;

public HelloWorldResource( @Context GraphDatabaseService database) {
  this.database = database;
}

@GET
@Produces( MediaType.TEXT_PLAIN )
@Path( "/{nodeId}" )
public Response hello( @PathParam( "nodeId" ) long nodeId ) {
    // Do stuff with the database
    return Response.status( Status.OK ).entity(
            ( "Hello World, nodeId=" + nodeId).getBytes() ).build();
}
}

Docs for writing plugins and extensions.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the answer, from looking through the links provided, I see your point. But where is the @Context-annotation coming from? Going back to my question, you cannot open a running REST-server with EmbeddedGraphDatabase?
Daniel: You might also want to look at the neo4j HA implementation - using that, you could run a database cluster where one of the cluster machines is a neo4j server instance, and the other is the "internal" database in your application.
Oh, and for your comment just now, there is a java client for the rest server that implements almost the same API as EmbeddedGraphDatabase (written by Michael Hunger, as a matter of fact:) ): github.com/jexp/neo4j-java-rest-binding
Ok, thanks a lot for all answers! Interesting project as well :)
@Context comes from Jersey, it is an annotation for their injection-points

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.