0

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!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So do I just need to loop through a JsonArray of the statements? Not sure how to structure of the body of the HttpBuilder
statements is an array. It's elements are maps consisting of statement and parameters entries. See gist.github.com/sarmbruster/9056261 for an example. This uses only 1 statement, but you should be able to adopt it easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.