Skip to content

Instantly share code, notes, and snippets.

@baskaufs
Created May 31, 2015 12:20
Show Gist options
  • Save baskaufs/cfd09ce81a776110b408 to your computer and use it in GitHub Desktop.
Save baskaufs/cfd09ce81a776110b408 to your computer and use it in GitHub Desktop.
URL to query the TDWG sandbox SPARQL endpoint
http://tdwg-rdf.phylodiversity.net/store2/sparql?query=SELECT%20DISTINCT%20%3Fimage%20WHERE%20%7B%3Chttp%3A%2F%2Fbioimages.vanderbilt.edu%2Find-baskauf%2F00000%3E%20%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fdepiction%3E%20%3Fimage.%7D
@baskaufs
Copy link
Author

Here is the encoded URL that performs the very simple SPARQL query (gist: test.sparql) to test retrieving results from the TDWG sandbox SPARQL endpoint.

Notes:

  1. The problem that I was having before was in getting the query string properly encoded for use in a URL. I solved that problem by converting the query to a single line (deleted linefeeds) and pasting it in the converter at http://meyerweb.com/eric/tools/dencoder/ . I then appended it to "query=" and placed it after the "?" in the URL.
  2. The file that is returned from the store2 endpoint is XML. If you change "store2" in the URL to "store3", the results come from the endpoint that returns JSON.
  3. Here is the relationship between what is happening here and what is happening in the cURL example. (See http://curl.haxx.se/docs/manpage.html for a summary of cURL options.) The --data option causes cURL to perform an HTTP POST request rather than an HTTP GET request. The POST method essentially sends a file to the server - in the case of the example, it is the file "test.sparql" after it was cleaned up by performing URL encoding to get rid of nasty characters like space, "{", "<", etc. The URL in this gist performs and HTTP GET request, which is the normal thing that happens when you put a URL in a browser URL box and click "load". The data after the query separator "?" is a key/value pair, with the key being "query" and the value being the URL-encoded query string. SPARQL endpoints can use either method, but POST is probably better since a GET via URL has privacy concerns as it can be cached and in some instances there is a limit to the length of the query string. These don't apply to POST requests.
  4. The next step in testing this would be to try sending the query using Javascript. There is an example using XMLHttpRequest at http://www.openjs.com/articles/ajax_xmlhttp_using_post.php . I probably won't have time to try this today, but I may try it later. Again, I'm unsure about what will happen with a cross-domain request. But the worst thing that could happen is that it would fail.

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