Reputation: 1589
Currently have built out in HttpBuilder:
def static query(statement, params,success, error, String _URL)
{
def http = new HTTPBuilder( _URL )
http.request( Method.POST, ContentType.JSON ) {
uri.path = '/db/data/cypher'
headers.'X-Stream' = 'true'
requestContentType = ContentType.JSON
body = [ query : statement , params : params ?: [:] ]
// uri.query = [ param : 'value' ]
response.success = { resp, json ->
if (success) success(json)
else {
println "Status ${resp.statusLine} Columns ${json.columns}\nData: ${json.data}"
}
}
response.failure = { resp, message ->
def result=[status:resp.statusLine.statusCode,statusText:resp.statusLine.reasonPhrase]
result.headers = resp.headers.collect { h -> [ (h.name) : h.value ] }
result.message = message
if (error) {
error(result)
} else {
println "Status: ${result.status} : ${result.statusText} "
println 'Headers: ${result.headers}'
println 'Message: ${result.message}'
}
}
}
}
Which can take in one query statement and one parameters map and spit out a response from the server. However I would like to input an array of queries and parameters (Such as a json array of each). I have tried looping through a json object in the body but to no avail. Any thoughts? Thanks!
Upvotes: 0
Views: 1022
Reputation: 39925
Neo4j 2.0 introduced a new "transactional HTTP endpoint". One of its capabilities is to pass in multiple cypher statements and multiple parameter sets. It's very well documented, so I suggest giving it a try.
Alternatively you can use batch operations to aggregate multiple calls to the "old" endpoint (/db/data/cypher
). However I'd suggest the first approach.
Upvotes: 2