How do I get useful data out of a SPARQL endpoint using javascript only? |
If your javascript is in a webpage hosted on a different domain, you have the usual cross-site request restriction. So first, how to get the response from the endpoint to your page:
If the answer is 3:
link
This answer is marked "community wiki".
Good point Keith -- fortunately bibliographica is CORS enabled. The other alternative is for the endpoint to support jsonp (though I'm not sure whether this is a standard for how endpoints support sparql).
(14 Jan '11, 19:03)
rgrp ♦♦
|
Here's an example piece of javascript (+ html) that talks to the Bibliographica SPARQL endpoint: http://bibliographica.org/demos/sparql.html This demo uses the 'figtrees' sparql js library: http://thefigtrees.net/lee/sw/sparql.js |
I think some SPARQL endpoints can be configured to return JSON, which can be pulled into a web page without cross-domain security restrictions getting in the way. One appraoch I have used it to run a SPARQL query using YQL and then grab the JSON response. For example, try a query of the form: select * from sparql.search where query=”YOUR_SPARQL_QUERY” and service=”SPARQL_ENDPOINT_URL” in the Yahoo Developer console [http://developer.yahoo.com/yql/console/] (See http://blog.ouseful.info/2010/11/02/accessing-linked-data-in-scraperwiki/ for a couple of examples.) Another tool I've used is SPARQLproxy [http://data-gov.tw.rpi.edu/ws/sparqlproxy.php] which lets you enter a query and endpoint, and get the result in a variety of formats, inclusing three different JSON formats (SPARQL JSON, MIT Simile/Exhibit JSON and Google Viz API JSON). |