add cart choropleth column cross cube error file folder geo help home lock obs poi rdf remove search slice spreadsheet success table unlock warning

[this is a icon-] developer tool

SPARQL 1.1 Query: Results

Edit query
Query results
s p_blank o_blank
http://opendatacommunities.org/id/geography/administration/lsoa/E01031397 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01031397 geosparql: asWKT MULTIPOLYGON (((-0.6448801043995614 50.83919980594249, -0.6464970012207336 50.83896715395098, -0.6460941914043978 50.83768773861428, -0.6469807647459173 50.83699128599998, -0.6479261099128858 50.8372988060858, -0.6511434983367996 50.83599879428577, -0.6521626374641264 50.83654457786924, -0.6571605959698489 50.83757344910796, -0.657624929543643 50.83820994157636, -0.6615558318502403 50.830366153442476, -0.6632179642919543 50.83284601115922, -0.6633162208516824 50.83576928315941, -0.6628425309467105 50.838375269447305, -0.6617538593337281 50.83930525229868, -0.661533581237607 50.84090822523988, -0.6617964016608201 50.84208547703891, -0.6601218684489017 50.842504157230024, -0.6582064792105792 50.84378627146015, -0.6576232053051996 50.84541090121013, -0.6568757009482105 50.84612175451394, -0.6570091188018053 50.846808591860416, -0.6561401543227698 50.84906573207054, -0.6587076005462204 50.84949816213647, -0.6584638585610347 50.848391924912534, -0.6617123636729904 50.847677198520564, -0.6628156940046207 50.84784729046764, -0.6637239125814753 50.848493437647896, -0.6653097754603956 50.84899894800416, -0.6719900669702321 50.84927732111891, -0.6734298650239217 50.84700134100311, -0.6756075312079173 50.846556879944494, -0.6774996881364016 50.84697064772837, -0.680736851726078 50.84636022371627, -0.682083409246131 50.84655704118228, -0.6815469855471213 50.84710536401108, -0.68270560806705 50.847325286175305, -0.6812401741844984 50.85042934835746, -0.6794979507747555 50.85024777656578, -0.6792737918073858 50.849633709368625, -0.6777311866781133 50.849427390333794, -0.6770725459854563 50.85011239672883, -0.6764198603508114 50.852092474520425, -0.6760222283701499 50.85409342773312, -0.6782523052857429 50.85413674061063, -0.677101418566701 50.8566237317756, -0.6781683303354276 50.858587320524684, -0.6785256078110641 50.860524882110234, -0.6773941236964931 50.862850273262275, -0.6773701147706384 50.863926717632125, -0.6717412327949854 50.864850851378655, -0.6625068905042629 50.86526076753717, -0.656920211806797 50.86627047381652, -0.6505359902143767 50.86679124199776, -0.6501391118064939 50.86670930609411, -0.6494509778822013 50.863413533117814, -0.6499678472446159 50.8617539623779, -0.6515649089471738 50.85969775272796, -0.6531608779510323 50.85579332172805, -0.6491425618747158 50.85500876197015, -0.6505808928029467 50.85258771205004, -0.6504899294247779 50.85120751441919, -0.6447484964742403 50.84985588609901, -0.6440921616885984 50.84946513139204, -0.6430230775559032 50.84738615582651, -0.643215252787556 50.84612541631843, -0.6434312385577766 50.84281781173014, -0.6448801043995614 50.83919980594249)))
SPARQL API: The Basics

The most flexible way to access the data is by using SPARQL, a query language, analagous to SQL for relational databases, for retrieving and manipulating data from graph databases like ours. We support SPARQL 1.1 query syntax. Many online tutorials are available.

To submit a SPARQL query from your code, you issue an HTTP GET or POST to our endpoint:http://opendatacommunities.org/sparql, with the query itself as a url-encoded parameter called query.

For example, to run the following simple SPARQL query and get the results as JSON:

SELECT * WHERE {?s ?p ?o} LIMIT 10

Option 1: POST (recommended)

Issue a POST to the endpoint, with the query in the body, and an Accept header of sparql-results+json:

POST http://opendatacommunities.org/sparql HTTP/1.1
Host: opendatacommunities.org
Accept: application/sparql-results+json
Content-Type: application/x-www-form-urlencoded

query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Option 2: GET

Issue a GET to the following URL (note the .json extension - see the formats section for more detail on this):

GET http://opendatacommunities.org/sparql.json?query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Scroll down to the end of this page for examples of both of these methods in a few different languages.

Results formats

As with other aspects of our API, to get the data in different formats, you can use either (a) a format extension or (b) an HTTP Accept header. Available result formats depend on the type of SPARQL query. There are four main forms:

SELECT queries return tabular results, and the formats available reflect this:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
CSV .csv text/csv

CONSTRUCT and DESCRIBE queries return graph data, so the results are available in the same formats as our resource APIs:

Format Extensions Accept Headers
RDF/XML .rdf application/rdf+xml
N-triples .nt, .txt, .text application/n-triples,
text/plain
Turtle .ttl text/turtle
JSON-LD .json application/ld+json,
application/json

ASK queries return a boolean result:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
Results pagination

We accept page and per_page parameters for paginating the results of SELECT queries (we automatically modify your query to apply LIMIT and OFFSET clauses). For other query types (i.e. DESCRIBE, CONSTRUCT, ASK), pagination like this doesn’t make so much sense, so these parameters are ignored.

For requests made through the website (i.e. HTML format), the page size is defaulted to 20. For requests to our sparql endpoint for data formats (i.e. non-HTML), there will be no defaults for these parameters (i.e. results are unlimited. For performance reasons we generally advise LIMITing your query if possible).

Parameter Substitution

You can parameterise your SPARQL by including %{tokens} in your queries, and providing values for the tokens in the request parameters.

Note that the following tokens are reserved and cannot be used as parameters for substitution:

  • controller
  • action
  • page
  • per_page
  • id
  • commit
  • utf8
  • query
Cross Origin Resource Sharing

Our servers are configured to allow access from all domains. This means that if you’re writing JavaScript to request data from our server in to a web page hosted on another domain, your browser should check this header and allow it.

If you need to support very old browsers, you can additionally pass a callback parameter and the results will be wrapped in that function. For example:

http://opendatacommunities.org/sparql.json?callback=myCallbackFunction&query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

This help topic on the jQuery website has more details.

Examples

Using cURL

Here’s a couple of examples running a query using the widely available cURL command line program.

Request the results as XML, using a POST:

curl -X POST -H "Accept: application/sparql-results+xml" -d "query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010" http://opendatacommunities.org/sparql

Request the results as JSON, using a GET:

curl -X GET -H "Accept: application/sparql-results+json" http://opendatacommunities.org/sparql?query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010

Using JavaScript

This example HTML page uses jQuery to issue a POST to our SPARQL endpoint, requesting the results as JSON.

<!DOCTYPE html>
<html lang='en'>
<head>
	<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
</head>
<body>
<script type='text/javascript'>

	var query = 'SELECT * WHERE {?s ?p ?o} LIMIT 10';
	var url = 'http://opendatacommunities.org/sparql.json';
	$.ajax({
		method: 'POST',
		dataType: 'json',
		url: url,
		data: {query: query},
		success: function(data) {
			alert('success: ' + data.results.bindings.length + ' results');
			console.log(data);
		}
	});
</script>
</body>
</html>