SPARQL Protocol

CVS Version:
$Id: Overview.html,v 1.15 2005/03/14 06:10:52 eric Exp $
Author:
Eric Prud'hommeaux, W3C

Abstract

The SPARQL Query Lanuage [SQ] defines a query service's response to a valid SPARQL query. SPARQL clients use the SPARQL Protocol to communiate these queries to services and accept the responses. The W3C has specified a language, WSDL 2.0 [WB] which can be used to define the syntax of protocols. This document defines a protocol by defining its syntax in WSDL 2.0. The semantics of the arguments are defined in this document.

Status of this Document

This documents experiments by the author. It is not endorsed by the W3C Team or Membership. It is hoped that the work described here will be useful to the Data Access Working Group.

Table of Contents

1. Introduction

SPARQL Protocol is a simple practical protocol for transporting SPARQL queries. It uses HTTP GET for the transport, a fixed character encoding of utf-8, and is described as a Web service with a WSDL 2.0 service description. This protocol defines a single message parameter, query, and a small numer of responses indicating successful processing or encountered errors. A query on a service is expressed as a URL. For example, a query:

SELECT * WHERE (?s ?p ?o)

on the service http://rdf.example/svc/ will be encoding with this URL:

http://rdf.example/svc/?query=SELECT%20%2A%20WHERE%20%28%3Fs%20%3Fp%20%3Fo%29

XForms [XF] defines a syntax for constructing a query URL from an {http location} (service URI) and a set of query parameters. This syntax is familiar to many web developers as it is practically identical to CGI parameters constructed by HTML forms. WSDL 2.0 uses the XForms syntax and defines a syntax for transporting message parameters and defining the response. Query services supporting SPARQL protocol can be described with WSDL 2.0.

Implementors of this protocol need only follow the query URI construction rules included in this document. They do not need to support any further XForms or WSDL processing. This document attempts to keep the implementation burden to a minimum by including the critical normative text from the referenced specifications.

2. Terms

This document introduces a small number of terms, defined here, to describe the mechanics of this protocol. For compatibility and clarity, some terms are adopted from other specifications (WSDL and XForms) and included here.

HTTP Location (service URI)
defined in WSDL Bindings [WB] —

an absolute or relative URI as defined by [IETF RFC 2396]. The value of this property specifies a template for the relative portion of the request URI for an operation. This URI is combined with the base URI specified in the {address} property of the endpoint element to form the full URI for the HTTP request to invoke the operation. It MUST contain an absolute or a relative URI, i.e. it MUST NOT include a fragment identifier in the URI.

3. SPARQL WSDL

This syntax of this protocol is defined as the protocol that is compatible with the SPARQL-P service description, which is excerpted and explained here:

<description targetNamespace='...SPARQL-WSDL2.xml' ...>

 <interface name='SPARQL'>
   <operation name='query'
              pattern='http://www.w3.org/2004/08/wsdl/in-out'
              style='http://www.w3.org/2004/08/wsdl/style/uri'>
     <input element='sl:query'/>
     <output element='xr:sparql rdf:RDF'/>
   </operation>
 </interface>

 <binding name='httpSparqlBinding'
          interface='SPARQL'
          type='http://www.w3.org/2004/08/wsdl/http'>
   <fault name="MalformedRequest" whttp:code='400'>
   <fault name="UnsupportedOperation" whttp:code='501'>
   <operation ref='sl:query'
      whttp:method="GET" >
   </operation>
 </binding>

</description>

This defines a service identified by http://.../SPARQL-WSDL2.xml which has a single input parameter called query (see X.0 Input). The XML Schema type [XS] of that parameter is xs:string. The response for a successfully processed request is an XML document with either a <result/> or <rdf:RDF/> root element. The meaning of these documents are described in X.0 Result Set Response and X.0 RDF Response respectively. The binding operation specifies a GET method. This is defined in X.0 HTTP Binding. The service description does not identify a particular {HTTP Location}. Different services will publish different {HTTP Locations}. These services may advertise the {HTTP Locations} via any conventional (e.g. via a complete WSDL 2.0 description, see X.0 SPARQL WSDL Service Description) or emergent means (e.g. via an RDF service description).

4. Input

The SPARQL Query string is byte-encoded in utf-8 and then url-encoded by the WSDL URL construction rules::

  1. XForms' section 11.6 Serialization as application/x-www-form-urlencoded

    Element nodes selected for inclusion are encoded as EltName=value{sep}, where = is a literal character, {sep} is the separator character from the separator attribute on submission, EltName represents the element local name, and value represents the contents of the text node. Note that contextual path information is not preserved, nor are namespaces or namespace prefixes. As a result, different elements might serialize to the same name.

    • The encoding of EltName and value are as follows: space characters are replaced by +, and then non-ASCII and reserved characters (as defined by [RFC 2396] as amended by subsequent documents in the IETF track) are escaped by replacing the character with one or more octets of the UTF-8 representation of the character, with each octet in turn replaced by %HH, where HH represents the uppercase hexadecimal notation for the octet value and % is a literal character. Line breaks are represented as "CR LF" pairs (i.e., %0D%0A).

  2. WSDL 2.0's section 3.8.1.2.1 Serialization in the request URI

    If the value of the {http location} property does not contain a "?" (question mark) character, one is appended. If it does already contain a question mark character, then an "&" separator character is appended. Each parameter pair is separated by the "&" separator character.

The choice of character encoding was motivated by the following guidelines from the Character Model specification [CM]:

C015  [S]  Specifications MUST either specify a unique character encoding, or provide character encoding identification mechanisms such that the encoding of text can be reliably identified.

C016  [S]  When designing a new protocol, format or API, specifications SHOULD require a unique character encoding.

C018  [S]  When a unique character encoding is required, the character encoding MUST be UTF-8, UTF-16 or UTF-32.

5. Responses

SPARQL Query [SQ] defines queries and identifies the response formats for successfully processed queries.

<description targetNamespace='...SPARQL-WSDL2.xml' ...>

 <interface name='SPARQL'>
   <operation name='query'
              pattern='http://www.w3.org/2004/08/wsdl/in-out'
              style='http://www.w3.org/2004/08/wsdl/style/uri'>
     <input element='sl:query'/>
     <output element='xr:sparql rdf:RDF'/>
   </operation>
 </interface>
 ...
</description>

SPARQL Query also identifies two error responses. These are identified with the faults UnsupportedOperation and MalformedRequest.

5.1 Result Set Response

SPARQL queries of the forms SELECT ... and ASK ... [SQ] yields tabular XML results [SR], represented by xr:sparql in the WSDL description.

<sparql xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result">
  <head><variable name="s"/>
        <variable name="p"/>
        <variable name="o"/></head>
  <results>
    <result><s bnodeid="b1">
            <p uri="http://xmlns.com/foaf/0.1/name"/>
            <o xml:lang="en">Bob</o></result>
    <result><s bnodeid="b1">
            <p uri="http://xmlns.com/foaf/0.1/mbox"/>
            <o uri="mailto:bob@example.com"/></result>
  </results>
</sparql>

This is indicated by xr:sparql in the WSDL 2.0 description.

5.2 RDF/XML Respones

SPARQL queries of the forms CONSTRUCT ... and DESCRIBE ... [SQ] yield RDF/XML results [RX], represented by rdf:RDF in the WSDL description.

<rdf:RDF xmlns="http://xmlns.com/foaf/0.1/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   <rdf:Description>
      <name>Bob</name>
      <mbox rdf:resource="mailto:bob@example.com"/>
   </rdf:Description>
</rdf:RDF>

This is indicated by rdf:RDF in the WSDL 2.0 description.

5.3 Error Responses

Errors resulting of SPARQL queries result in HTTP errors with a string containing an error description (in sl:faultDetails). The HTTP error code is specified by the whttp:code attribute.

<UnsupportedOperation>
   <faultDetails>http://my.example/functions#even</faultDetails>
<UnsupportedOperation>

6. HTTP Binding

The reference service description asserts that there is a GET operation for transporting SPARQL queries. A service with an {http location} http://rdf.example/svc/ and a SPARQL Query "SELECT * WHERE (?s ?p ?o)" will have the following bytes on the wire:

GET /svc/?query=SELECT%20%2A%20WHERE%20%28%3Fs%20%3Fp%20%3Fo%29 HTTP/1.1
Host: rdf.example

A Service that uses WSDL 2.0 to describe this service would use:

<description ...
 xmlns:generic='http://lists.w3.org/Archives/Public/public-rdf-dawg/2005JanMar/att-0205/SPARQL-WSDL2.xml'>
 <import namespace='http://lists.w3.org/Archives/Public/public-rdf-dawg/2005JanMar/att-0205/SPARQL-WSDL2.xml'
    location='http://lists.w3.org/Archives/Public/public-rdf-dawg/2005JanMar/att-0205/SPARQL-WSDL2.xml'/>

 <binding name='httpSparqlBinding'>
           interface='generic:SPARQL'
   <operation ref='sl:query' whttp:location="query"
      whttp:method="GET" >
   </operation>
 </binding>

 <service>
   <endpoint name='EP'
             binding='sl:httpSparqlBinding'
             address='http://rdf.example/svc/'>
   </endpoint>
 </service>
</description>

8. Service Descriptions

Different services may publish variants of the binding in order to add information that they need for processing. This is defined by WSDL but repeated here. A service may, for instance, offer a parser that supports more than one language. This service is free to define a binding with an additional parameter to identify the language:

<description ... 
  xmlns:generic='http://lists.w3.org/Archives/Public/public-rdf-dawg/2005JanMar/att-0205/SPARQL-WSDL2.xml'>
 <import namespace='http://lists.w3.org/Archives/Public/public-rdf-dawg/2005JanMar/att-0205/SPARQL-WSDL2.xml'
    location='http://lists.w3.org/Archives/Public/public-rdf-dawg/2005JanMar/att-0205/SPARQL-WSDL2.xml'/>

 <binding name='httpSparqlBinding'
           interface='generic:SPARQL'>
   <operation ref='sl:query' whttp:location="query?lang=sparql"
      whttp:method="GET" >
   </operation>
 </binding>

  <service>
   <endpoint name='EP'
             binding='sl:httpSparqlBinding'
             address='http://rdf.example/svc/'>
   </endpoint>
  </service>
 <interface>
<description>

A client calling this service will see follow the WSDL URL construction rules, producing a query as such:

GET /svc/?lang=sparql&query=SELECT%20%2A%20WHERE%20%28%3Fs%20%3Fp%20%3Fo%29 HTTP/1.1
Host: rdf.example

While the service is defined by WSDL, the client need not process WSDL. A client may learn about a query service from an RDF service description or a user interface. The {http location} of a service is the concatonation of the operation location to the endpoint address. For example the above has a {http location} of the above interface is:

http://rdf.example/svc/?lang=sparql

9. References

9.1 Normative References

[SQ]
SPARQL Query, E. Prud'hommeaux, A. Seaborne, Authors. World Wide Web Consortium, 15 March 2001. This version of the SPARQL Query Working Draft is http://www.w3.org/TR/rdf-sparql-query/ . The latest version of SPARQL Query is available at http://www.w3.org/TR/2005/WD-rdf-sparql-query-20050217/ .
[SR]
SPARQL Variable Binding Results XML Format, D Beckett, Author. World Wide Web Consortium, 15 March 2001. This version of the SPARQL Variable Binding Results XML Format Working Draft is http://www.w3.org/TR/rdf-sparql-XMLres/ . The latest version of SPARQL Variable Binding Results XML Format is available at http://www.w3.org/TR/2004/WD-rdf-sparql-XMLres-20041221/ .
[WB]
Web Services Description Language (WSDL) Version 2.0 Part 3: Bindings, H Haas, et al, Authors. World Wide Web Consortium, 15 March 2001. This version of the Web Services Description Language (WSDL) Version 2.0 Part 3: Bindings Working Draft is http://dev.w3.org/cvsweb/~checkout~/2002/ws/desc/wsdl20/wsdl20-bindings.html . The latest version of Web Services Description Language (WSDL) Version 2.0 Part 3: Bindings is available at http://www.w3.org/2002/ws/desc/wsdl20-bindings .
[XF]
XForms 1.0, M. Dubinko, et al., Editors. World Wide Web Consortium, 14 October 2003. This version of the XForms 1.0 Recommendation is http://www.w3.org/TR/2003/REC-xforms-20031014/ . The latest version of XForms 1.0 is available at http://www.w3.org/TR/xforms/ .
[XS]
XML Schema Part 2: Datatypes, P. Byron and A. Malhotra, Editors. World Wide Web Consortium, 2 May 2001. This version of the XML Schema Part 2 Recommendation is http://www.w3.org/TR/2001/REC-xmlschema-2-20010502 . The latest version of XML Schema Part 2 is available at http://www.w3.org/TR/xmlschema-2/ .
[CM]
Character Model for the World Wide Web 1.0: Fundamentals, Martin J. Dürst et al., Editors. World Wide Web Consortium, 15 February 2005. This version of the Character Model for the World Wide Web is http://www.w3.org/TR/2005/REC-charmod-20050215/ . The latest version of the Character Model is available at http://www.w3.org/TR/charmod/ .

9.2 Informative References

[Canonical XML]
Canonical XML, J. Boyer, Author. World Wide Web Consortium, 15 March 2001. This version of the Canonical XML Recommendation is http://www.w3.org/TR/2001/REC-xml-c14n-20010315. The latest version of Canonical XML is available at http://www.w3.org/TR/xml-c14n.
[IETF RFC 2119]
Key words for use in RFCs to Indicate Requirement Levels, S. Bradner, Author. Internet Engineering Task Force, June 1999. Available at http://www.ietf.org/rfc/rfc2119.txt.
[IETF RFC 2388]
Returning Values from Forms: multipart/form-data, L. Masinter, Author. Internet Engineering Task Force, August 1998. Available at http://www.ietf.org/rfc/rfc2388.txt.
[IETF RFC 2616]
Hypertext Transfer Protocol -- HTTP/1.1, R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, T. Berners-Lee, Authors. Internet Engineering Task Force, June 1999. Available at http://www.ietf.org/rfc/rfc2616.txt.
[IETF RFC 2617]
HTTP Authentication: Basic and Digest Access Authentication, J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A. Luotonen, L. Stewart, June 1999. Available at http://www.ietf.org/rfc/rfc2616.txt.
[IETF RFC 2818]
HTTP Over TLS, E. Rescorla, Author. Internet Engineering Task Force, May 2000. Available at http://www.ietf.org/rfc/rfc2818.txt.
[IETF RFC 2965]
HTTP State Management Mechanism, D. Kristol, L. Montulli Authors. Internet Engineering Task Force, October 2000. Available at http://www.ietf.org/rfc/rfc2965.txt.
[IETF RFC 3023]
XML Media Types, M. Murata, S. St. Laurent, D. Kohn, Authors. Internet Engineering Task Force, January 2001. Available at http://www.ietf.org/rfc/rfc3023.txt.
[IETF RFC 3986]
Uniform Resource Identifiers (URI): Generic Syntax, T. Berners-Lee, R. Fielding, L. Masinter, Authors. Internet Engineering Task Force, January 2005. Available at http://www.ietf.org/rfc/rfc3986.txt.
[SOAP 1.2 Part 1: Messaging Framework]
SOAP Version 1.2 Part 1: Messaging Framework, M. Gudgin, M. Hadley, N. Mendelsohn, J-J. Moreau, H. Frystyk Nielsen, Editors. World Wide Web Consortium, 24 June 2003. This version of the "SOAP Version 1.2 Part 1: Messaging Framework" Recommendation is http://www.w3.org/TR/2003/REC-soap12-part1-20030624/. The latest version of "SOAP Version 1.2 Part 1: Messaging Framework" is available at http://www.w3.org/TR/soap12-part1/.
[SOAP 1.2 Part 2: Adjuncts]
SOAP Version 1.2 Part 2: Adjuncts, M. Gudgin, M. Hadley, N. Mendelsohn, J-J. Moreau, and H. Frystyk Nielsen, Editors. World Wide Web Consortium, 7 May 2003. This version of the "SOAP Version 1.2 Part 2: Adjuncts" Recommendation is http://www.w3.org/TR/2003/REC-soap12-part2-20030624/. The latest version of "SOAP Version 1.2 Part 2: Adjuncts" is available at http://www.w3.org/TR/soap12-part2/.
[XML 1.0]
Extensible Markup Language (XML) 1.0 (Third Edition), T. Bray, J. Paoli, C. M. Sperberg-McQueen, E. Maler, and F. Yergeau, Editors. World Wide Web Consortium, 4 February 2004. This version of the XML 1.0 Recommendation is http://www.w3.org/TR/2004/REC-xml-20040204/. The latest version of "Extensible Markup Language (XML) 1.0" is available at http://www.w3.org/TR/REC-xml.
[XML Information Set]
XML Information Set, J. Cowan and R. Tobin, Editors. World Wide Web Consortium, 24 October 2001. This version of the XML Information Set Recommendation is http://www.w3.org/TR/2001/REC-xml-infoset-20011024. The latest version of XML Information Set is available at http://www.w3.org/TR/xml-infoset.
[XML Schema Structures]
XML Schema Part 1: Structures, H. Thompson, D. Beech, M. Maloney, and N. Mendelsohn, Editors. World Wide Web Consortium, 2 May 2001. This version of the XML Schema Part 1 Recommendation is http://www.w3.org/TR/2001/REC-xmlschema-1-20010502. The latest version of XML Schema Part 1 is available at http://www.w3.org/TR/xmlschema-1.
[WSDL 2.0 Core Language]
Web Services Description Language (WSDL) Version 2.0 Part 1: Core Language, R. Chinnici, M. Gudgin, J-J. Moreau, S. Weerawarana, Editors. World Wide Web Consortium, @@ @@@@ @@@@. This version of the "Web Services Description Language (WSDL) Version 2.0 Part 1: Core Language" Specification is available is available at wsdl20.html. The latest version of "Web Services Description Language (WSDL) Version 2.0 Part 1: Core Language" is available at http://www.w3.org/2002/ws/desc/wsdl20.
[WSDL 2.0 Predefined Extensions]
Web Services Description Language (WSDL) Version 2.0 Part 2: Predefined Extensions, M. Gudgin, A. Lewis, and J. Schlimmer, Editors. World Wide Web Consortium, @@ @@@@ @@@@. This version of the "Web Services Description Language (WSDL) Version 2.0 Part 2: Predefined Extensions" Specification is available at wsdl20-extensions.html. The latest version of "Web Services Description Language (WSDL) Version 2.0 Part 2: Predefined Extensions" is available at http://www.w3.org/2002/ws/desc/wsdl20-extensions.
[SOAP Message Transmission Optimization Mechanism]
SOAP Message Transmission Optimization Mechanism, N. Mendelsohn, M. Nottingham, and H. Ruellan, Editors. World Wide Web Consortium, W3C Recommendation, 25 January 2005. This version of SOAP Message Transmission Optimization Mechanism is http://www.w3.org/TR/2005/REC-soap12-mtom-20050125/. The latest version of the "SOAP Message Transmission Optimization Mechanism" document is available from http://www.w3.org/TR/soap12-mtom/.
[MTXML]
Assigning Media Types to Binary Data in XML, A. Karmarkar, Ü. Yalçınalp, W3C Working Draft, 2 November 2004. The latest version of the "Assigning Media Types to Binary Data in XML" document is available from http://www.w3.org/TR/xml-media-types/.
[WSDL 2.0 Primer]
Web Services Description (WSDL) Version 2.0 Part 0: Primer, K. Sankar, K. Liu, D. Booth, Editors. World Wide Web Consortium, 21 December 2004. This version of Web Services Description (WSDL) Version 2.0 Part 0: Primer is http://www.w3.org/TR/2004/WD-wsdl20-primer-20041221/. The latest version of the "Web Services Description Version 2.0 Part 0: Primer" document is available from http://www.w3.org/2002/ws/desc/wsdl20-primer.

$Date: 2005/03/14 06:10:52 $