Created
November 15, 2011 06:33
-
-
Save FaKod/1366334 to your computer and use it in GitHub Desktop.
Create and delete Neo4j Nodes via REST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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