Skip to content

Instantly share code, notes, and snippets.

Created Nov 15, 2011
What would you like to do?
Create and delete Neo4j Nodes via REST
case class MatrixNodeProperties(name: String, profession: String)
object CreateAndDeleteNodes extends App with Rest with SimpleWebResourceProvider {
// base location of Neo4j server instance
override def baseUriAsString = "http://localhost:7474/db/data/"
// all subsequent REST calls should use JSON notation
override val mediaType = Some(MediaType.APPLICATION_JSON)
// yes I want so see HTTP logging output
override def enableLogFilter = true
rest {
implicit s =>
// defining node names and profession
val nodes = ("Mr. Andersson", "Hacker") ::
("Morpheus", "Hacker") ::
("Trinity", "Hacker") ::
("Cypher", "Hacker") ::
("Agent Smith", "Program") ::
("The Architect", "Whatever") :: Nil
// for all notes
val locations =
for (_@(name, prof) <- nodes;
// create node
cr = "node".POST[ClientResponse] <= MatrixNodeProperties(name, prof)
// if creation was successful use yield
if (cr.getStatus == ClientResponse.Status.CREATED.getStatusCode)
// yield all created locations
) yield cr.getLocation
// print them to console
locations.foreach(s => println("created node path: " + s.getPath))
// and remove them
for (location <- locations)
(location.toString).DELETE <=()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment