Skip to content

Instantly share code, notes, and snippets.

@LaurensRietveld
Last active August 29, 2015 14:07
Show Gist options
  • Save LaurensRietveld/eebde750f87c52cdfa58 to your computer and use it in GitHub Desktop.
Save LaurensRietveld/eebde750f87c52cdfa58 to your computer and use it in GitHub Desktop.
#YASQE: Update YASQE configuration via ajax call

In some use cases, it is useful to fetch the YASQE configuration from an external URL. This allows you to e.g. fetch the shown YASQE query from an externally hosted page. This might be interesting when you've published your SPARQL queries in separate files as part of your documentation, and you would like to use YASQE as a means of accessing it. This example gist does exactly that: when a 'queryRef' URL parameter is passed, it fetches the YASQE query with an asynchronous call from the URL.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Parsing URL arguments for YASQE</title>
<link href='http://cdn.jsdelivr.net/yasqe/2.0/yasqe.min.css' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="yasqe"></div>
<!-- include three libs in 1 request (see https://github.com/jsdelivr/jsdelivr#url-structure for more info) -->
<script src="http://cdn.jsdelivr.net/g/[email protected],[email protected],[email protected]"></script>
<script src="yasqeInit.js"></script>
</body>
var consumeUrl = function(yasqe, args) {
//change query and endpoint value if there are any
if (args.query) yasqe.setValue(args.query);
if (args.endpoint) yasqe.options.sparql.endpoint = args.endpoint;
//want to consume other arguments such as the request type (POST/GET), or arguments to send to endpoint
//feel free to add them in this function as well.
//as you see, all options you can specify in the default settings, are configurable via yasqe.options as well
//Or, if you want to configure yasqe via a remote url (e.g. a query in some file elsewhere),
//feel free to do so!
//This example uses a cors proxy to access a github file containing a query
if (args.queryRef) $.get(args.queryRef, function(result){yasqe.setValue(result);});
};
var yasqe = YASQE(document.getElementById("yasqe"), {
sparql: {
showQueryButton: true
},
consumeShareLink: consumeUrl
});
@jneubert
Copy link

Thanks a lot! With the kind help of Laurens, I've created a public hub for executing queries on GitHub at http://zbw.eu/beta/sparql-gui. It can be used (without any warranty) to execute arbitrary queries saved on GitHub via a query like this:

http://zbw.eu/beta/sparql-gui/?endpoint=http://zbw.eu/beta/sparql/stwv/query&queryRef=https://api.github.com/repos/jneubert/skos-history/contents/sparql/count_added_concepts.rq

to execute the query at https://github.com/jneubert/skos-history/blob/master/sparql/count_added_concepts.rq on the endpoint given in the URL. (For more stuff like this, see expample queries for the skos-history projekt.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment