3

I am wondering how I get access to my (example)dataset that I have on Neo4j through Javascript, i.e. I have a movie dataset, so I would like to get and receive queries through an local html page? As you might wonder, I am a very beginner to this and I really appreciate it if someone would explain it to me step by step :)

Thanks in advance

Y_Lakdime
  • 825
  • 2
  • 15
  • 33

3 Answers3

2

You can access your Neo4j graph database through the http transactional endpoint

http://neo4j.com/docs/stable/rest-api-transactional.html

and issue cypher queries to query your graph.

As it is a http endpoint, you can access it with normal ajax requests, an e.g. with jquery

var body = JSON.stringify({
                statements: [{
                    statement: 'MATCH (n) RETURN count(n)'
                }]
            });
$.ajax({
            url: "http://localhost:7474",
            type: "POST",
            data: body,
            contentType: "application/json"
        })
            .done(function(result){
                console.log(result);

            })
            .fail(function(error){
                console.log(error.statusText);
            });
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36
  • Should I add this between the script tags? – Y_Lakdime Nov 30 '14 at 13:07
  • Hi, I created a new HTML5 project in NetBeans, inserted this code in between the – Y_Lakdime Nov 30 '14 at 14:09
  • This is the normal behavior. Don't take my words negative but using a database comes after learning at least one programming language, maybe you should first learn html/js/ajax and then you should be able to try neo4j. If you already know one programming language other than js, try maybe first to use it for connecting to neo4j, there is for sure a driver available. – Christophe Willemsen Nov 30 '14 at 15:12
  • I already have a good understanding of html/js/java/python/json. But I really cant have a hold on this. Could you please provide me a step by step guide on how to accomplish this? – Y_Lakdime Dec 01 '14 at 11:40
  • With "http://localhost:7474" i get XML Parsing Error: no root element found , i changed it to "http://localhost:7678" – A.HADDAD Jan 14 '19 at 21:04
  • i found in https://neo4j.com/developer/javascript/ that you use http://localhost:7474/db/data/transaction/commit i tried it and i get unauthorized how can i pass my authontifcation in the uri – A.HADDAD Jan 14 '19 at 21:38
0

With a local html page, I assume you mean jquery ?

In general for Javascript there are a number of drivers for neo4j, see http://neo4j.com/developer/javascript

If you want to look for jquery, check out http://jexp.github.io/cy2neo (source: https://github.com/jexp/cy2neo/blob/master/scripts/neo.js#L7)

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
0

Note you need to add "authentifcation" too, it's done by an ajax function called beforeSend:

beforeSend: function (xhr) {
                xhr.setRequestHeader ("Authorization", "Basic " + btoa("neo4j"+ ":" + "yourNeo4jPassword"));
            }}

also the path to the database is "http://localhost:7474/db/data/transaction/commit" and not "http://localhost:7474/"

So the final Solution is :

$.ajax({
            url: "http://localhost:7474/db/data/transaction/commit",
            type: "POST",
            data: body,
            contentType: "application/json",
            beforeSend: function (xhr) {
                xhr.setRequestHeader ("Authorization", "Basic " + btoa("neo4j"+ ":" + "password"));
            }}
            )
            .done(function(result){
                 console.log(result);
            }) 
            .fail(function(error){
                console.log(error.statusText);
            });
A.HADDAD
  • 1,809
  • 4
  • 26
  • 51