SPARQL Protocol

Created on Feb. 23, 2013, 11:55 a.m. by Hevok & updated by Hevok on May 2, 2013, 5:20 p.m.

As SPARQL defines also a Protocol, a SPARQL Endpoint is addressed via HTTP. What one need to make a Query to a SPARQL Endpoint is first of course the Web address of a SPARQL Endpoint, so one needs its URL. Then in the SPARQL Endpoint one has to name also graphs one wants to Query. In the end on needs the Query String. One can put all three parts together, first of all the address of the SPARQL Endpoint in the SPARQL Query which is nothing else then an extended URI that will be put through via HTTP to the SPARQL Endpoint. So one has the base part which is the SPARQL Endpoint, a question mark and after it parameters. There one has the named Graph that one addresses. One is not able to use special characters in the parameter, like the slash or the colon for example so one has to take into account that one uses here the ampersand encoding. After the Graph that one is questioning the next Parameter is the SPARQL Query Expression. In the Query one has the keyword query that equals for instance the SELECT Statement and here also the entire statement has to be ampersand encoded, for instance for empty or white space one takes a plus sign an other symbols that are not available and cannot be used for an URI. The encoding is a little bit difficult and there are lot of routines that are able to transform a regular String into to this kind of Encoding.

  • Method to Query/respond of SPARQL queries via http
  • A SPARAQL URI consists out of 3 parts:
    1. URL of a SPARQL endpoint (e.g. http://example.org/sparql)
    2. RDF Graph(s) to be queried (optional, part of the Query string e.g. named-graph-uri=http://example.org/data.rdf)
    3. Query string (part of the Query string, e.g. query=SELECT...)

http://example.org/sparql?name-graph-uri=http%3A%2F%2example.org%2Fdata&]query=SELECT+...

The SPARQL SELECT Statement within the HTTP result in Trace with a GET Request to a SPARQL Endpoint, the entire Query and the host name where the SPARQL Endpoint is located. The use agent is for example the program.

In return from the SPARQL Endpoint one gets a response. If it was a success one gets a 200 code which means everything is OK and one receives an answer within this request. Then one gets a date and a server where the SPARQL Endpoint is located as well as one gets the Content Type which will be Application SPARQL Results and XML so one is able to know how to decode the SPARQL results that is transfered next as an XML with an header of the Variables and the in the results the Variable bindings. With this one can interpret the results accordingly.

  • Simple SPARQL Query

    PREFIX dc: <http://purl.org/dc/elements/1.1/>]
    SELECT ?book ?who
    WHERE { ?book dc:creator ?who }
    
  • HTTP Trace of the SPARQL Query

    GET /sparql/?query=EndedQuery&defualt-graph-uri=http://www.other.example/books HTTP/1.1
    Host: www.other.example
    User-agent: my-sparql-client/0.1
    
  • HTTP Trace of the SPARQL Response

    HTTP/1.1 200 OK
    Date Future
    Server Comanche/2.5 (Unix)
    Connection: close
    Content-Type: application/sparql-results+xml
    <?xml version="1.0"?>
    <sparql xmlns="htt://www.w3.org/2005/sparql-results#">
    ...
    
sparql-protocol.png

Tags: definition, web, coding, programming, information
Categories: Tutorial
Parent: SPARQL

Update entry (Admin) | See changes

Comment on This Data Unit