Created
February 22, 2012 10:52
-
-
Save timhodson/1884117 to your computer and use it in GitHub Desktop.
Kasabi: Quick example of using the sparql API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######################################## | |
| ## Quick curl commands | |
| ######################################## | |
| # get the response as RDF | |
| curl -v -X GET "http://api.kasabi.com/dataset/airlines/apis/sparql?query=describe%20?s1%20where%20%7B%0A%20%20?s1%20a%20%3Chttp://xmlns.com/foaf/0.1/Organisation%3E%20.%0A%20%20%7D%0ALimit%2010&output=rdf&apikey=$KASABI_API_KEY" | |
| # get the response as JSON | |
| curl -v -X GET "http://api.kasabi.com/dataset/airlines/apis/sparql?query=describe%20?s1%20where%20%7B%0A%20%20?s1%20a%20%3Chttp://xmlns.com/foaf/0.1/Organisation%3E%20.%0A%20%20%7D%0ALimit%2010&output=json&apikey=$KASABI_API_KEY" | |
| ######################################## | |
| ## Javascript and jQuery based example | |
| ######################################## | |
| $('document').ready(function() { | |
| var apibase, apikey, sparqlQuery, url; | |
| apikey = "MYSECRETKEY"; | |
| apibase = "http://api.kasabi.com"; | |
| sparqlQuery = encodeURI("describe ?s1 where {\n ?s1 a <http://xmlns.com/foaf/0.1/Organisation> .\n }\nLimit 10"); | |
| url = "" + apibase + "/dataset/airlines/apis/sparql?query=" + sparqlQuery + "&output=json" + apikey; | |
| $('.foo').append("<code>Request: " + url + "</code>"); | |
| return $.ajax({ | |
| url: url, | |
| success: function(data) { | |
| var k, v, _results; | |
| _results = []; | |
| for (k in data) { | |
| v = data[k]; | |
| if (data[k]['http://xmlns.com/foaf/0.1/name'] != null) { | |
| $('.foo').append("<h2>" + data[k]['http://xmlns.com/foaf/0.1/name'][0]['value'] + "</h2>"); | |
| } | |
| if (data[k]['http://vocab.org/transit/terms/icaoCode'] != null) { | |
| $('.foo').append("<p> ICAO Code: " + data[k]['http://vocab.org/transit/terms/icaoCode'][0]['value'] + "</p>"); | |
| } | |
| if (data[k]['http://vocab.org/transit/terms/iataCode'] != null) { | |
| _results.push($('.foo').append("<p> IATA Code: " + data[k]['http://vocab.org/transit/terms/iataCode'][0]['value'] + "</p>")); | |
| } else { | |
| _results.push(void 0); | |
| } | |
| } | |
| return _results; | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment