example of Java Rest API wrapper

1,618 views
Skip to first unread message

Alex Frieden

unread,
Apr 2, 2013, 3:23:10 PM4/2/13
to ne...@googlegroups.com
Hi all, trying to get a good example of using the Java REST API wrapper to just connect to the database

http://m2.neo4j.org/content/repositories/releases/org/neo4j/neo4j-rest-graphdb/1.8.1/

Using my database at http://localhost:7474/

Thanks!

Rahul Deshmukh

unread,
Apr 2, 2013, 3:32:22 PM4/2/13
to ne...@googlegroups.com
Hello Alex,
Even i am looking for the example.Please let me know if you find any answer and i will also search and let u know if i find something.
Thanks


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
With regards,
Rahul Deshmukh
017691387831

Michael Hunger

unread,
Apr 2, 2013, 8:14:00 PM4/2/13
to ne...@googlegroups.com
it is on m2.neo4j.org

depedency:

<dependency>
  <groupId>service.local.repositories.releases.content.org.neo4j</groupId>
  <artifactId>neo4j-rest-graphdb</artifactId>
  <version>1.9.M04</version>
</dependency>


RestAPI rest = new RestAPIFacade("http://localhost:7474/db/data");

Result<Map<String,Object>> result = rest.query("start n=node({id}) return n",map("id",0));

for (Map<String,Object> row : result) {
   Node n=row.get("n");
   // do something
}

HTH

Michael

Alex Frieden

unread,
Apr 3, 2013, 10:20:31 AM4/3/13
to ne...@googlegroups.com
This did not work (Result not known type and there was a problem with the map method)

Michael Hunger

unread,
Apr 4, 2013, 4:55:57 AM4/4/13
to ne...@googlegroups.com
Use this:

import org.neo4j.rest.graphdb.RestAPI;
import org.neo4j.rest.graphdb.RestAPIFacade;
import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
import org.neo4j.rest.graphdb.util.QueryResult;

import java.util.Map;

import static org.neo4j.helpers.collection.MapUtil.map;

public class RestApiTest {
    public static void main(String[] args) {
        final RestAPI api = new RestAPIFacade("http://localhost:7474/db/data");
        final RestCypherQueryEngine engine = new RestCypherQueryEngine(api);
        final QueryResult<Map<String,Object>> result = engine.query("start n=node({id}) return n.name, id(n) as id", map("id", 0));
        for (Map<String, Object> row : result) {
            long id=((Number)row.get("id")).longValue();
            String name= (String) row.get("n.name");

Alex Frieden

unread,
Apr 4, 2013, 11:20:01 AM4/4/13
to ne...@googlegroups.com
Awesome!  Thank you so much.  Running into another issue now:  I am running an augmentation of this


import org.neo4j.rest.graphdb.RestAPI;
import org.neo4j.rest.graphdb.RestAPIFacade;
import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
import org.neo4j.rest.graphdb.util.QueryResult;

import java.util.Map;

import static org.neo4j.helpers.collection.MapUtil.map;

public class TestRun {
    public static void main(String[] args) {
        System.out.println("starting test");
        final RestAPI api = new RestAPIFacade("http://localhost:7474/db/data");
        System.out.println("API created");
        final RestCypherQueryEngine engine = new RestCypherQueryEngine(api);
        System.out.println("engine created");
        final QueryResult<Map<String,Object>> result = engine.query("start n=node({id}) return n, id(n) as id;", map("id", 0));
        System.out.println("query created");
        for (Map<String, Object> row : result) {
            long id=((Number)row.get("id")).longValue();
            System.out.println("id is " + id);
        }
    }
}

And it seems to just be stalling at the construction of the QueryResult.  Any idea why it would just get stuck there?  No error or exception.  

Alessandro Negro

unread,
Apr 7, 2013, 6:20:43 PM4/7/13
to ne...@googlegroups.com
Hi Alex,
we have just released a simple java client for Neo4J.
Have a look at it since there are some usage examples.


Reco4J is a recommender engine but the client is a general purpose java client for Neo4J.

Let me know,
Alessandro
Reply all
Reply to author
Forward
0 new messages