Minimal Groovy neo4j client

@Grab(‘org.codehaus.groovy.modules.http-builder:http-builder:0.7.2’)
import groovyx.net.http.RESTClient
import groovy.json.JsonSlurper

def authToken = ‘neo4j:password’.bytes.encodeBase64().toString()
def auth = “Basic: $authToken”.toString()
// send Cypher statement to Neo4j Server
def client = new RESTClient( ‘http://localhost:7474’, ‘application/json’ )
client.defaultRequestHeaders.’Authorization’ = auth

def body = “””{
“statements” : [ {
“statement” : “CREATE (wordsworth:Author {firstname:’William’, lastname: ‘Wordsworth’})”
} ]
}”””
def resp = client.post( path : ‘/db/data/transaction/commit’, body : body )

println resp.data.toString()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s