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/E01020229 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01020229 geosparql: asWKT MULTIPOLYGON (((-3.4469222188392625 50.617134272134024, -3.4451987158122592 50.61310210325944, -3.4442105412966275 50.60728374225298, -3.444648746361208 50.60562616039887, -3.443672976170066 50.60158927745974, -3.44260252826882 50.60248932141449, -3.4421310345224607 50.602459184566456, -3.4398577137508033 50.60413855456801, -3.4361842611100863 50.60578927953926, -3.4354570356700225 50.60659778381312, -3.431290653784218 50.60775796816774, -3.4303381665136023 50.607154498634976, -3.4284398419117923 50.60784421942612, -3.4275702660378675 50.60899796165363, -3.427436765271938 50.610563608355115, -3.429259536844409 50.61120051363281, -3.429700671108266 50.61190470747679, -3.4283853959866617 50.61243797850736, -3.426881920066674 50.613385452423316, -3.425854416189308 50.613294602699796, -3.424550694564508 50.61121950602635, -3.4296485743865017 50.60538581490775, -3.432598550896943 50.60307956201874, -3.4376872416017457 50.60001837289794, -3.4395709986825516 50.598587632448805, -3.439293910310698 50.5980271676059, -3.4419568110193204 50.5966667922331, -3.442919774000815 50.59581307472767, -3.4433560044904508 50.593755570393945, -3.4441778213038323 50.59213712723935, -3.4478655361318813 50.59047714777717, -3.449102567591509 50.593596591937754, -3.4504645387807504 50.5947522918163, -3.451836631835377 50.594891032414914, -3.451896360151184 50.59545417474004, -3.4539307389100222 50.59590545222877, -3.4567430234174674 50.59546559547321, -3.4577442918233796 50.5957172170937, -3.4619407368447495 50.59596918076856, -3.462634868780546 50.594696272594945, -3.4635671163558657 50.593671198609144, -3.463153176910414 50.59328491617339, -3.4649251838678867 50.59255708994192, -3.464033709612022 50.59110491006571, -3.4629885288444453 50.59265813977058, -3.461289520604167 50.59267256963619, -3.4600767392360927 50.59155175175547, -3.4610973449950424 50.59157089253481, -3.4610827266990833 50.59078507709677, -3.462481771317064 50.59010337291532, -3.463070692788108 50.58988093144033, -3.46284887568814 50.58883055147148, -3.4639272064315256 50.588572798198584, -3.464925742500113 50.58982889726845, -3.466497077387301 50.58919424217506, -3.4679105069051896 50.58823906978787, -3.4693626097909473 50.58946394605536, -3.474273024079285 50.59035246211355, -3.478184427417864 50.59164290401268, -3.480421661250896 50.59270270503704, -3.4809984186215135 50.59352278827227, -3.4819017268424206 50.59394299200585, -3.482953013215667 50.5914293865918, -3.4823234542791237 50.58982756756857, -3.4822122037977397 50.58763457184094, -3.4816798645522162 50.58642722571569, -3.4802492222470875 50.584952503440896, -3.4808953148299957 50.58357436368116, -3.4816087172432946 50.582823992144604, -3.483372529968706 50.58220304440725, -3.4852373806207964 50.58316176192931, -3.4872194815878594 50.58497725807771, -3.489264091720025 50.587770403720945, -3.4897538470711797 50.58923028902147, -3.4909032571687257 50.590369148113616, -3.4923343823140627 50.59307087043253, -3.4932559653614303 50.595571567722665, -3.4965542246532144 50.600523948145366, -3.4984666646042566 50.60203578792677, -3.4961692986851634 50.60225898075786, -3.490736401307705 50.60422877606355, -3.48860760933582 50.605342344860865, -3.4887340319461058 50.60722039915604, -3.4878621693995875 50.609065338207664, -3.487601825745763 50.61144261692978, -3.4829206232873835 50.610253289670965, -3.4800430794454127 50.61000034541546, -3.472419228571163 50.61279721286713, -3.4695634338721675 50.61250825469778, -3.466716355208591 50.61282428766828, -3.464787840199251 50.613661300496155, -3.464417876446739 50.614619692723736, -3.4617453071734663 50.6150702196549, -3.4609443758294005 50.6149391796563, -3.46046432348357 50.61556920746008, -3.4589474709466352 50.61575615288809, -3.458510730408868 50.615275203485346, -3.4562439627641504 50.6160810940943, -3.4560327577568177 50.61670809209158, -3.4533951800437643 50.61663811361597, -3.4528551969064543 50.617062140009374, -3.449813272992 50.61774808872242, -3.449099736158024 50.61737122423649, -3.4469222188392625 50.617134272134024)))
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>
<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>