Any example clients for REST API?


#21

First and foremost, thanks marco for your support. For those who may be interested in browser based queries to try with other vis libraries such as D3 or cytoscape.js, the below seems to work:

function queryGrakn(url, query) {
  // Default options are marked with *
    return fetch(url, {
        method: "POST",
        mode: "cors", // no-cors, cors, *same-origin
        credentials: "omit", // include, same-origin, *omit
        headers: {
            "Content-Type": "text/plain; charset=UTF-8",
        },
        body: query, // body data type must match "Content-Type" header
    })
    .then(function(response) {
        console.log(response)
        return response.json();
    })
    .then(function(json) {
        console.log(json);
        return json;
        
    })
    .catch(error => console.error(`Fetch Error =\n`, error));
};

// Test
var url = 'http://localhost:4567/kb/grakn/graql?infer=true&defineAllVars=true'
var qry = 'match $x isa person, has identifier $n; offset 0; limit 30; get;';
queryGrakn(url, qry);

The result is a JSON form that can be readily parsed for follow-on manipulation. Probably obvious to most but sharing for others who may be skill challenged like me.

Cheers,

JB