user3816378
user3816378

Reputation: 93

How to use Apache Marmotta SPARQL webservice api with AngularJS?

I want to execute the sample SPARQL query for apache marmotta from AngularJS controller via SPARQLs marmotta webservice. Sample code:

var url = "http://localhost:8080/marmotta/";
var query = "SELECT * WHERE { ?subject ?property ?object }"
$http.post(url+"sparql/select",{
     'output': "json",
     'query': query
 } ).then(function(data){
        $scope.hello = data;
 }).catch(function(error){
        alert(error);
 });

I recieve 'query not supported' then 500 SyntaxError:

SyntaxError: Unexpected token q at Object.parse (native) at fromJson (http://localhost:63342/ws/app/script/angular.js:1075:14) at defaultHttpResponseTransform (http://localhost:63342/ws/app/script/angular.js:8650:16) at http://localhost:63342/ws/app/script/angular.js:8735:12 at forEach (http://localhost:63342/ws/app/script/angular.js:326:20) at transformData (http://localhost:63342/ws/app/script/angular.js:8734:3) at transformResponse (http://localhost:63342/ws/app/script/angular.js:9464:23) at processQueue (http://localhost:63342/ws/app/script/angular.js:13292:27) at http://localhost:63342/ws/app/script/angular.js:13308:27 at Scope.$get.Scope.$eval (http://localhost:63342/ws/app/script/angular.js:14547:28)

Or when I use code like this:

var url = "http://localhost:8080/marmotta/";
var query = "SELECT * WHERE { ?subject ?property ?object }";
$http.get(url+"sparql/select/query="+query+"&output='json'")
.then(function(data){
     $scope.hello = data;
}).catch(function(error){
        $scope.hello = error.stack;
});

I get a 404. Any ideas how to properly use SPARQL WS API?

Upvotes: 0

Views: 564

Answers (3)

Fernando Sumba
Fernando Sumba

Reputation: 21

In meteor plataform it works, using the package "http" and call a web service of Apache Marmotta.

HTTP.call("GET", "http://IP:8080/sparql/select", {
    params: {
        "query": "select * where {?s ?p ?o } limit 10",
        "output": "xml"
    }
}, function(error, result) {
    console.log(result);
});

Upvotes: 0

Prasetiady
Prasetiady

Reputation: 1

I had same problem earlier. But actually i found the solution by checking ajax request that generated by apache marrmotta web application. Here sample request that works for me

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://localhost:8080/marmotta/sparql/select",
  "method": "POST",
  "headers": {
    "content-type": "application/sparql-query;charset=UTF-8",
    "accept": "application/sparql-results+json"
  },
  "data": "SELECT * WHERE { ?s ?p ?o } LIMIT 10"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

I think the main problem is the headers.

Upvotes: 0

wikier
wikier

Reputation: 2566

Because the SPARQL endpoint is actually located at http://localhost:8080/marmotta/sparql/select.

You should have that documentation in the SPARQL module in Marmotta.

Upvotes: 0

Related Questions