How to

Query data.open.ac.uk with SPARQL

data.open.ac.uk provides access to a number of datasets using the Resource Description Framework (RDF). In RDF, each dataset is a graph consisting of a collection of triples. data.open.ac.uk datasets are stored in the same database ("quad store") so they can be queried together. SPARQL is the query language for interacting with RDF databases. The SPARQL specifications cover a query language, query response f ormats, and a protocol for interacting with SPARQL endpoints using HTTP. data.open.ac.uk exposes a SPARQL endpoint accessible at /sparql (or /query).

Query methods and parameters

A SPARQL endpoint accepts a single query parameter whose value should be a valid, URL-encoded SPARQL query (see also the SPARQL 1.1 Protocol). Request formats can be requested using HTTP Content Negotiation (recommended). An optional output parameter may be used to request a specific response format without using HTTP Content Negotiation. < /p>

The following table summarises the API parameters:

Parameter Description Required?
query The SPARQL query to execute. If not provided, then the endpoint will return a query interface (when HTML is requested) or a SPARQL Service Description document (when an RDF format is requested). No
output With this parameter users can override normal HTTP based Content Negotiation to request results in a specific response format No

Response codes

The endpoint is published with HTTP, so agents should support any valid HTTP response code. The following table summarises the most frequent response codes and the meaning that they have in this context:

Code Description
200 Request has been successful
400 Invalid request. E.g. an invalid or missing SPARQL query
405 Method not allowed. Request used an unsupported HTTP method, e.g. DELETE or PUT
500 A server error happened when querying the quad store

Query types

Access to data.open.ac.uk endpoint is publicly provided in a read-only mode. A SPARQL query that is submitted to the endpoint may be of the following types:

  • SELECT
  • ASK
  • CONSTRUCT
  • DESCRIBE

Details about the above query types can be found on the SPARQL Query specification

Response formats

The response format depends on the type of query that is sent to the service.

SELECT and ASK queries return a tabular result set, available in a number of standard SPARQL formats, detailed in the table below. Similarly, CONSTRUCT AND DESCRIBE queries return an RDF graph, that can be returned in a number of different RDF seriali sations

The primary method of selecting a response format is using Http Content Negotiation, ie specify the Accept header in the HTTP request. However, this can be overridden using the output parameter.

Query Type Accept header Output parameter Format
ASK or SELECT application/sparql-results+xml xml SPARQL XML Results Format
ASK or SELECT application/sparql-results+json json SPARQL JSON Results Format
SELECT text/csv csv SPARQL CSV Results Format
CONSTRUCT or DESCRIBE text/turtle ttl Turtle
CONSTRUCT or DESCRIBE application/rdf+xml rdf RDF/XML
CONSTRUCT or DESCRIBE application/json json RDF/JSON