Skip to main content

How to Use the SPARQL Endpoint

Abstract

How to Use the SPARQL Endpoint

Currently, the SPARQL endpoint can be accessed via a web interface linked from every project's frontend page.

Additional to that, it can be used as an HTTP web service. By posting required parameters to the endpoint it will return the result of the SPARQL query in a specified format.

Note

You can use POST and GET for posting queries to the SPARQL endpoint. For longer queries POST should be used.

See HTTP Web Services Based on the SPARQL Endpoint for details.

See below for a detailed description:

Parameter

Required

Description

query

yes

contains the entire SPARQL query. See here for details.

limitations: only SELECT and DESCRIBE/CONSTRUCT queries are allowed at the moment.

queryname

yes, if query is null

the name of a named query that is defined in the SesameSetup.xml

If a query name AND a query parameter is given, the named query is preferred.

Either the query OR the query name parameter have to be set.

[parameter]

no

A parameter that is used when a named query is specified with 'queryname' that requires parameters.

content-type

no

Specifies the content type of the returned data. If no content-type is passed, text/xml will be used.

The PoolParty project SPARQL endpoint also supports the CSV (comma separated values) and TSV (tab separated values) content types as output format. Please keep in mind when specifying the output format you have to write out the format, e.g. text/tab-separated-values.

template

no

name of a local Velocity template or URL to a velocity template located on

an openly accessible server.

For these content-types there is already a predefined way of rendering the results:

  • application/xml (rendered and returned as XML)

  • application/json (rendered and returned as JSON)

  • html/table

Note

Only SELECT queries can be formatted with velocity templates. When the template parameter is used you also have to specify the content-type parameter. The content type has to be set to the content type produced by the velocity template.

Errors:

If an error occurs, either the HTTP status code 400 or 500 will be returned, an error message is provided to identify the exact problem.

Common errors are listed below:

Error

Status Code

Description

Template Error

400 Bad Request

The template specified in the template parameter could not be found or contains errors.

See error message or log files for specific information.

Invalid Query

400 Bad Request

The query was malformed or could not be evaluated.

See error message or log files for specific information.

Internal Error

500 Internal Server Error

An exception occured while processing the request.

See error message or log files for specific information.

Limitations:

  • The query timeout is set to 300 sec (=5 min). Queries that take longer than that will be aborted after 300 sec to ensure availability and performance of the system services.

  • SELECT query results are limited to 500. Although you can send multiple queries and split up the results with the LIMIT and OFFSET modifiers (see SPARQL specification).

Example

GET

http://vocabulary.semantic-web.at/PoolParty/sparql/semweb?query=SELECT%20%3Fs%20%3Fp%20%3Fo%20WHERE%20%7B%20%3Fs%20%3Fp%20%3Fo%20%7D%20LIMIT%2050%20OFFSET%200&content-type=application%2Fjson

POST

POST http://vocabulary.semantic-web.at/PoolParty/sparql/semweb
content-type application/x-www-form-urlencoded

query=SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 50 OFFSET 0&content-type=application/json

Example With Query Parameter

As described here queries defined in the SesameSetup.xml can have parameters (defined as %%%URI%%% in this example).

<entry>
        <key>DataOfSingleConcept</key>
        <value>
                <sparqlQueryParameterMap>
                        <entry>
                                <key>URI</key>
                                <value>&lt;http://vocabulary.semantic-web.at/semweb/308&gt;</value>
                        </entry>
                </sparqlQueryParameterMap>
                <sparqlQueryTemplate>
                        PREFIX skos: &lt;http://www.w3.org/2004/02/skos/core#&gt;
                        PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
                        SELECT ?Predicate ?Object
                        WHERE
                                {
                                %%%URI%%% ?Predicate ?Object
                                FILTER ( ?Predicate != rdf:type &amp;&amp; ?Predicate != skos:semanticRelation)
                                }
                </sparqlQueryTemplate>
        </value>
</entry>

The call to the SPARQL endpoint using this query and the providing the query parameter would look like this:

http://vocabulary.semantic-web.at/PoolParty/sparql/semweb?queryname=DataOfSingleConcept&URI=<http://vocabulary.semantic-web.at/semweb/307>

In the REST Console browser extension this can be tested in the following way.

Define the URL of the API call and the method POST:

23901021.png

Set the Content-Type of the body to 'application/x-www-form-urlencoded' and pass the SPARQL query in the body:

23901022.png

Don't forget that the PoolParty API requires authentication (Basic Auth):

23901055.png