You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Laura Morales <la...@mail.com> on 2017/04/05 06:18:27 UTC
Querying Fuseki
The documentation says to use
$ s-query --service http://localhost:3030/ds/query 'SELECT * {?s ?p ?o}'
this works great from the command line, but I'm not sure how to query my server from another application, for example from jQuery (ajax). Is there an example somewhere of the HTTP request that I'm supposed to send?
Thanks a lot.
Re: Querying Fuseki
Posted by Osma Suominen <os...@helsinki.fi>.
Hi Laura!
05.04.2017, 09:18, Laura Morales kirjoitti:
> The documentation says to use
>
> $ s-query --service http://localhost:3030/ds/query 'SELECT * {?s ?p ?o}'
>
> this works great from the command line, but I'm not sure how to query my server from another application, for example from jQuery (ajax). Is there an example somewhere of the HTTP request that I'm supposed to send?
This is all documented in the SPARQL 1.1 Protocol specification:
https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/
Basically to execute a SPARQL query you send either a GET or POST
request with a "query" parameter containing the actual query string.
Here is an example of querying a SPARQL endpoint using jQuery:
https://github.com/NatLibFi/Finto-data/blob/master/tools/ysa-to-yso/ysa-to-yso.js#L207
However, you may be better off using a JavaScript SPARQL library. There
are many such libraries available (search for "jquery sparql" or
"javascript sparql") but I can't recommend any specific one since I
haven't really used them myself.
-Osma
--
Osma Suominen
D.Sc. (Tech), Information Systems Specialist
National Library of Finland
P.O. Box 26 (Kaikukatu 4)
00014 HELSINGIN YLIOPISTO
Tel. +358 50 3199529
osma.suominen@helsinki.fi
http://www.nationallibrary.fi
Re: Querying Fuseki
Posted by "Bruno P. Kinoshita" <ki...@apache.org>.
The URL you mentioned is the Query endpoint for the ds dataset. The same page in the documentation mentions the other possible endpoints.
Fuseki itself is a good example. It is a web application, written with HTML and JavaScript (Backbone.JS and Marionette to be more specific).
Assuming you have Fuseki running, and can query your datasets with it, you can open the browser console, and look at the network tab to see the requests being sent to the server. For instance, I went to Fuseki and executed the query you used as example. Then right clicked the request in the network tab [1], and then Copy as cURL:
curl 'http://localhost:3030/test/query' -H 'Host: localhost:3030' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: application/sparql-results+json,*/*;q=0.9' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: http://localhost:3030/dataset.html?tab=query&ds=/test' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data 'query=SELECT+*+%7B%3Fs+%3Fp+%3Fo%7D'
If I copy and paste this into the command line in my Linux, I get a valid JSON response. You can use a similar approach to build your application with jQuery.
Hope that helps
Bruno
[1] http://imgur.com/a/smo6l
________________________________
From: Laura Morales <la...@mail.com>
To: jena-users-ml <us...@jena.apache.org>
Sent: Wednesday, 5 April 2017 6:18 PM
Subject: Querying Fuseki
The documentation says to use
$ s-query --service http://localhost:3030/ds/query 'SELECT * {?s ?p ?o}'
this works great from the command line, but I'm not sure how to query my server from another application, for example from jQuery (ajax). Is there an example somewhere of the HTTP request that I'm supposed to send?
Thanks a lot.