Andrew Malcolm
Andrew Malcolm

Reputation: 99

Sending SPARQL update query to Graphdb from Angular

I am trying to send an UPDATE (insert) to a Graphdb instance, starting from an ANGULAR web-application (typescript). Therefore i would need to create a HTTP GET request but I cannot work out how to correctly format that http request inside the ANGULAR application. Most tutorials online work with .JSON files to get/post data, not with RDF graphs.

I was hoping to do this through 'curl' and somehow start a curl-command from within angular, but i cannot even get the curl command to work inside my own console. I have followed this Guide and sifted through stackoverflow answers until i came to the following command for SPARQL UPDATE for graphDB:

curl -G -H "Accept:application/x-trig" 
-d update=INSERT+DATA+%7B%3Chttp%3A%2F%2Fexample%2F3aan%3E+dc%3Atitle+%22pullnaam%22%7D+
http://localhost:7200/repositories/myrepository/statements

When i execute this command, the console returns all resources/nodes inside the graph, but doesn't actually execute the Update inside the curl command.

Any help would be greatly appreciated and I apologise in advance if I've forgotten to add something crucial. I'm testing out some more variations on the curl command and hope to edit this question soon.

Thanks in advance!

Edit: working curl command is:

curl -X POST -G -H "Accept:application/x-trig" -d
update=INSERT+DATA+%7B%3Chttp%3A%2F%2Fexample%2F4aan%3E+dc%3Atitle+%22pullnaam%22%7D+ 
http://localhost:7200/repositories/myrepository/statements

Edit: working POST command inside typescript/angular is:

function(event){
const body = "update=INSERT+DATA+%7B%3Chttp%3A%2F%2Fexample%2Ftesteroo%3E+dc%3Atitle+%22pullnaam%22%7D+";
const headers = new HttpHeaders().set('Accept', 'application/x-trig').set('Content-Type','application/x-www-form-urlencoded');
let options = { headers:HttpHeaders};
var url = "http://128.199.58.129:7200/repositories/repo/statements";
return this.http.post(url,body,{headers:headers}).toPromise().then(function(response) { console.log(response.toString())});
}

Upvotes: 0

Views: 898

Answers (1)

Jeen Broekstra
Jeen Broekstra

Reputation: 22042

You're getting back statements because you are doing a GET request against the /statements resource. A SPARQL update is a POST request. You need to add -X POST to your curl request.

Upvotes: 2

Related Questions