Skip to content
mdeiters edited this page Sep 13, 2010 · 12 revisions

neo4jr-social is meant to be a simple service offering basic neo4j persistance and querying capabilities in a language agnostic way. You will likely want to do more advance things like custom traversing of your graph. To support this neo4jr-social auto loads extensions from a predefined location. Using this option allows you to add arbitrary methods to the neo4jr-social service.

How to configure extensions

  • By default neo4jr-social will load any jruby (files ending in .rb) files located at:
    ~/.neo4jr-social
  • You can also specify a different location to load ruby files from by setting the neo4jr_extensions environment variable. i.e.
    export neo4jr_extensions=/path/to/your/extensions
  • Or for you java people out there, you can set system property neo4jr.extensions

Example Extension

Creating extensions are super easy, especially if you already know ruby and the Sinatra library. In your action you have full access to the running neo4j database through the neo4jr-simple API (http://github.com/mdeiters/neo4jr-simple).

  • Create a new ruby file i.e.
    vi ~/.neo4jr-social/test.rb
  • Paste the following into test.rb,

    module Neo4jr
    class Service < Sinatra::Base
    get ‘/my_custom_action/:node_id’ do
    node = Neo4jr::DB.execute do |neo|
    neo.getNodeById(params[‘node_id’].to_s)
    end
    node.to_json
    end
    end
    end
  • Restart the service
  • Test the new GET request. Since i have the service running at http://localhost:8988/neo4jr-social/ I can access my new action at http://localhost:8988/neo4jr-social/my_custom_action/123