Skip to content

Instantly share code, notes, and snippets.

@sarmbruster
Created March 31, 2014 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarmbruster/9901244 to your computer and use it in GitHub Desktop.
Save sarmbruster/9901244 to your computer and use it in GitHub Desktop.
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6')
@Grab(group='net.sf.json-lib', module='json-lib', version='2.2.3', classifier='jdk15')
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*
def http = new RESTClient( 'http://localhost:7474/db/data/transaction/commit', JSON)
http.setProxy('localhost', 8888, 'http')
def response = http.post(body: [
statements: [
[
statement: 'CREATE (n {props}) RETURN n' ,
parameters: [
props : [
numericProp: 1,
stringProp: '1',
// mixedArrayProp: [1, 'abc'] // uncommenting this line gives "Collections containing mixed types can not be stored in properties."
anotherStringProp: "[1, 'abc']" // this stores a string property
]
]
]
]
])
assert response.status == 200
println "Location Header: $response.headers.Location"
def data = response.data.results.data[0]
println "result columns: ${response.data.results.columns[0]}"
println "we have ${data.size()} result rows"
data.eachWithIndex { row, index ->
println "result ${index}: $row.row"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment