= neo4jr-social Neo4jr-Social is a self contained HTTP REST + JSON interface to the graph database Neo4j. Neo4jr-Social supports simple dynamic node creation, building relationships between nodes and also includes a few common social networking queries out of the box (i.e. linkedin degrees of seperation and facebook friend suggestion) with more to come. Think of Neo4jr-Social is to Neo4j like Solr is to Lucene. Neo4jr-Social was built in JRuby but is language agnostic and is designed to run under Jetty or Tomcat. = Getting Started === Prerequisites * Java * JRuby: http://jruby.org === Installing Install Ruby Gem: json_pure jgem install json_pure Install Ruby Gem: sinatra jgem install sinatra Install Ruby Gem: neo4jr-simple jgem install neo4jr-simple Install Ruby Gem: neo4jr-social jgem install neo4jr-simple === Starting Neo4jr-Social After installing the above gems, an executable 'start-neo4jr-social' should be in your path. This will start the service and the database and listen for HTTP requests on localhost at port 8988: start-neo4jr-social -p8988 You can also start the service and specify the directory of where the neo4j database is stored or where to create a new database. If you omit this setting a database will be created in your tmp directory and destroyed when you shutdown the server. start-neo4jr-social -p8988 -dsome_relative_or_absolute_directory Run start-neo4jr-social --help to see all options === API Overview All results returned will be in JSON ==== GET /info Returns details about the Neo4j database like the location of the database and the number of nodes. ==== GET /nodes Returns all nodes in the database. Use this method with caution, this could crash your server if you have a database with more then a few thousand nodes. ==== POST /nodes Creates a new node in the neo4j database. Any parameters based in the body of the POST will be treated as properties for the node and will be stored in the database. ==== GET /nodes/:node_id Returns the properties for the specified node, where :node_id is the numeric id for the node ==== PUT /nodes/:node_id Updates the properties of the specified node, where :node_id is the numeric id for the node. Any parameters pased in the body of the PUT will be treated as properties for the node. If you add a new parameters (i.e. age=4) which previously were not on the node, neo4jr-social will still add that property to the node. ==== DELETE /nodes/:node_id Deletes the specified node, where :node_id is the numeric id for the node. ==== POST /nodes/:node_id/relationships Creates a relations for the specified node, where :node_id is the numeric id for the node. This is how you designate how two nodes are related to each other. * Required: to - this is the node id of the node you want to make a relationship to. This is a one-way relationship. If you want both nodes to be related to each other you will need to make individual POSTs for each direction of the relationship. * Required: type - this is the type of the relationship, i.e. 'friends'. This can be any string that is sensible in your domain. * Optional: Any other parameters you supply in the body of the POST will be added as properties to the relationship. For example if you were making 'friend' relationships and wanted to add a date since the friendship started you could pass a 'since' parameter in the POST. ==== GET /nodes/:node_id/relationships Returns relationships to other nodes for the specified node, where :node_id is the numeric id for the node. * Optional: type - Specify a type if only certain relationships are of interest ==== GET /nodes/:node_id/paths This returns all the ways two nodes are connected to each other and is similar to LinkedIn's degrees of separation. * Required: to - the id of the node that your trying to find a path to from the starting node, :node_id * Required: type - the type of relationships between nodes to follow * Optional: depth - maximum degrees of separation to find, the default is 2 degrees. Note: There may be performance impacts if this number is to high. * Optional: direction - What direction of relationships to follow, the default is 'both' ==== GET /nodes/:node_id/shortest_path This returns the shortest path of two nodes that are connected to each other * Required: to - the id of the node that your trying to find a path to from the starting node, :node_id * Required: type - the type of relationships between nodes to follow ==== GET /nodes/:node_id/recommendations This returns node suggestions for the given :node_id. This is similar to facebook friend suggestions where your friend's friends that your not friends with are suggested to you. * Required: type - the type of relationships between nodes to follow * Optional: level - the degree of separation that you want recommendations for, the default is 1 degree away which is similar to facebook's behavior == Troubleshooting /usr/bin/env: jruby: No such file or directory You need to either install jruby or if you used a utility like rvm then your jruby executable may actually be called jruby-1.4, if this is the case create an alias somewhere in your PATH == Contributors ====Matthew Deiters * Twitter : http://twitter.com/mdeiters * GitHub : https://github.com/mdeiters * LinkedIn : http://www.linkedin.com/in/matthewdeiters * Blog : http://www.theagiledeveloper.com == Copyright Copyright (c) 2009 Matthew Deiters. See LICENSE for details.