SPARQL 1.1 Protocol @import url("local.css");
code { font-family: monospace; }
div.constraint, div.issue, div.note, div.notice { margin-left: 2em; }
ol.enumar { list-style-type: decimal; } ol.enumla { list-style-type: lower-alpha; } ol.enumlr { list-style-type: lower-roman; } ol.enumua { list-style-type: upper-alpha; } ol.enumur { list-style-type: upper-roman; }
div.exampleInner pre { margin-left: 1em; margin-top: 0em; margin-bottom: 0em} div.exampleOuter {border: 4px double gray; margin: 0em; padding: 0em} div.exampleInner { background-color: #d5dee3; border-top-width: 4px; border-top-style: double; border-top-color: #d3d3d3; border-bottom-width: 4px; border-bottom-style: double; border-bottom-color: #d3d3d3; padding: 4px; margin: 0em } div.exampleWrapper { margin: 4px } div.exampleHeader { font-weight: bold; margin: 4px}
em.rfc2119 { text-transform: lowercase; font-variant: small-caps; font-style: normal; } This version: http://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/ Latest version: http://www.w3.org/TR/sparql11-protocol/ Previous version: http://www.w3.org/TR/2013/PR-sparql11-protocol-20130129/ Editors: Lee Feigenbaum, Cambridge Semantics <[email protected]> Gregory Todd Williams, Rensselaer Polytechnic Institute <[email protected]> Kendall Grant Clark, 1st Edition, Clark & Parsia LLC <[email protected]> Elias Torres, 1st Edition, IBM Corporation <[email protected]> Please refer to the errata See also translations Copyright W3C ® MIT ERCIM Keio Beihang liability trademark document use The SPARQL Protocol and RDF Query Language ( SPARQL RDF W3C SPARQL Working Group Semantic Web Activity activity statement May Be Superseded This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index Set of Documents This document is one of eleven SPARQL 1.1 Recommendations produced by the SPARQL Working Group SPARQL 1.1 Overview SPARQL 1.1 Query Language SPARQL 1.1 Update SPARQL1.1 Service Description SPARQL 1.1 Federated Query SPARQL 1.1 Query Results JSON Format SPARQL 1.1 Query Results CSV and TSV Formats SPARQL Query Results XML Format (Second Edition) SPARQL 1.1 Entailment Regimes SPARQL 1.1 Protocol SPARQL 1.1 Graph Store HTTP Protocol No Substantive Changes There have been no substantive changes to this document since the previous version change log color-coded diff Please Send Comments Please send any comments to [email protected] public archive SPARQL Working Group errata [email protected] public archive Endorsed By W3C This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web. Patents This document was produced by a group operating under the 5 February 2004 W3C Patent Policy public list of any patent disclosures Essential Claim(s) section 6 of the W3C Patent Policy 1 Introduction Document Conventions Terminology SPARQL Protocol Operations query operation query via GET query via POST with URL-encoded parameters query via POST directly Specifying an RDF Dataset Accepted Response Formats Success Responses Failure Responses update operation update via POST with URL-encoded parameters update via POST directly Specifying an RDF Dataset Success Responses Failure Responses Determining the Base IRI Example SPARQL Protocol Requests (informative) Examples of SPARQL Query SELECT with service-supplied RDF Dataset SELECT with simple RDF Dataset CONSTRUCT with simple RDF dataset and HTTP content negotiation ASK with simple RDF Dataset DESCRIBE with simple RDF Dataset SELECT with complex RDF Dataset SELECT with query-only RDF Dataset SELECT with ambiguous RDF Dataset SELECT with malformed query fault SELECT with query request refused fault Long SELECT query using POST with URL encoding Long SELECT query using direct POST SELECT with internationalization Examples of SPARQL Update UPDATE using URL-encoded parameters UPDATE using POST directly UPDATE specifying dataset and using POST directly Multi-operation UPDATE using URL-encoded parameters Multi-operation UPDATE specifying dataset and using URL-encoded parameters Multi-operation UPDATE specifying dataset and using POST directly Policy Considerations Security Conformance Changes Since Previous Recommendation (Informative) A References Normative References Other References This document describes the SPARQL 1.1 Protocol, a means of conveying SPARQL queries and updates from clients to SPARQL processors. The SPARQL Protocol has been designed for compatibility with the SPARQL 1.1 Query Language SPARQL SPARQL 1.1 Update Language for RDF The SPARQL Protocol consists of two HTTP operations: a query operation update operation A separate document describes the SPARQL 1.1 Graph Store HTTP Protocol When this document uses the words must must not should should not may recommended RFC 2119 RFC2119 SPARQL Protocol client An HTTP client (as defined by RFC 2616 RFC2616 client SPARQL Protocol service An HTTP server that services HTTP requests and sends back HTTP responses for SPARQL Protocol operations. The URI at which a SPARQL Protocol service listens for requests is generally known as a SPARQL endpoint. (Also known as: service SPARQL endpoint The URI at which a SPARQL Protocol service listens for requests from SPARQL Protocol clients. SPARQL Protocol operation An HTTP request and response that conform to the protocol defined in this document. RDF Dataset A collection of a default graph and zero or more named graphs, as defined by the SPARQL 1.1 Query Language The SPARQL Protocol consists of two operations: query and update. A protocol operation defines combinations of: The HTTP method by which the request is sent. The HTTP query string parameters included in the HTTP request URI. The message content included in the HTTP request body. The message content included in the HTTP response body. The SPARQL 1.1 Protocol is built on top of HTTP. All HTTP requirements for requests and responses must query The query MUST must query may default-graph-uri named-graph-uri SPARQL XML Results Format SPARQL JSON Results Format SPARQL CSV/TSV Results Format query form SPARQL content negotiation RFC2616 HTTP Method Query String Parameters Request Content Type Request Message Body query via GET GET query default-graph-uri named-graph-uri None None query via URL-encoded POST POST None application/x-www-form-urlencoded URL-encoded, ampersand-separated query parameters. query default-graph-uri named-graph-uri query via POST directly POST default-graph-uri named-graph-uri application/sparql-query Unencoded SPARQL query string The query must query Protocol clients may must percent encode query parameter RFC3986 HTTP query string parameters must & The HTTP request MUST NOT query Protocol clients may must percent encode RFC3986 application/x-www-form-urlencoded must & must application/x-www-form-urlencoded query Protocol clients may must must application/sparql-query may default-graph-uri named-graph-uri A SPARQL query is executed against an RDF Dataset default-graph-uri named-graph-uri FROM FROM NAMED must Note that a service may If an RDF Dataset is not specified in either the protocol request or the SPARQL query string, then implementations may Protocol clients should content negotiation RFC2616 The SPARQL Protocol uses the response status codes defined in HTTP to indicate the success or failure of an operation. Consult the HTTP specification RFC2616 should may The response body of a successful query operation with a 2XX response is either: a SPARQL Results Document in XML JSON CSV/TSV SELECT ASK an RDF graph [ RDF-CONCEPTS RDF/XML syntax RDF-XML DESCRIBE CONSTRUCT The content type of the response to a successful query operation must be the media type defined for the format of the response body. The HTTP response codes applicable to an unsuccessful query operation include: 400 if the SPARQL query supplied in the request is not a legal sequence of characters in the language defined by the SPARQL grammar; or, 500 if the service fails to execute the query. SPARQL Protocol services may also return a 500 response code if they refuse to execute a query. This response does not indicate whether the server may or may not process a subsequent, identical request or requests. The response body of a failed query request is implementation defined. Implementations may A protocol service may update The update must must update may using-graph-uri using-named-graph-uri HTTP Method Query String Parameters Request Content Type Request Message Body update via URL-encoded POST POST None application/x-www-form-urlencoded URL-encoded, ampersand-separated query parameters. update using-graph-uri using-named-graph-uri update via POST directly POST using-graph-uri using-named-graph-uri application/sparql-update Unencoded SPARQL update request string The update must update Protocol clients may must percent encode RFC3986 application/x-www-form-urlencoded must & must application/x-www-form-urlencoded update Protocol clients may must must application/sparql-update may using-graph-uri using-named-graph-uri SPARQL Update requests are executed against a Graph Store, a mutable container of RDF graphs managed by a SPARQL service. The WHERE DELETE/INSERT operation UPDATE RDF Dataset USING USING NAMED WITH using-graph-uri using-named-graph-uri It is an error to supply the using-graph-uri using-named-graph-uri USING USING NAMED WITH A SPARQL Update processor should treat each occurrence of the using-graph-uri=g USING <g> using-named-graph-uri=g USING NAMED <g> The SPARQL Protocol uses the response status codes defined in HTTP to indicate the success or failure of an operation. Consult the HTTP specification RFC2616 should may The response body of a successful update request is implementation defined. Implementations may The HTTP response code for an unsuccessful update request should be: 400 if the SPARQL update request string is not a legal sequence of characters in the language defined by the SPARQL Update grammar; or, 500 if the service fails to execute the update request. SPARQL Protocol services may also return a 500 response code if they refuse to execute an update request. This response does not indicate whether the server may or may not process a subsequent, identical request or requests. The response body of a failed update request is implementation defined. Implementations may A protocol service may The BASE Uniform Resource Identifier (URI): Generic Syntax RFC3986 must may The following HTTP trace examples illustrate invocation of the query update In some examples the string " EncodedQuery UnencodedQuery For query This SPARQL query PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?book ?who WHERE { ?book dc:creator ?who } is conveyed via HTTP GET to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query That query against the service-supplied RDF Dataset, executed by that SPARQL query service, returns the following query result: HTTP/1.1 200 OK Date: Fri, 06 May 2005 20:55:12 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head> <variable name="book"/> <variable name="who"/> </head> <results> <result> <binding name="book"><uri>http://www.example/book/book5</uri></binding> <binding name="who"><bnode>r29392923r2922</bnode></binding> </result> ... </sparql> This SPARQL query PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?book ?who WHERE { ?book dc:creator ?who } is conveyed to the SPARQL query service, http://www.other.example/sparql/ GET /sparql/? query default-graph-uri That query — against the RDF Dataset identified by the value of the default-graph-uri http://www.other.example/books HTTP/1.1 200 OK Date: Fri, 06 May 2005 20:55:12 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="book"/> <variable name="who"/> </head> ... </sparql> This SPARQL query PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX myfoaf: <http://www.example/jose/foaf.rdf#>
CONSTRUCT { myfoaf:jose foaf:depiction <http://www.example/jose/jose.jpg>. myfoaf:jose foaf:schoolHomepage <http://www.edu.example/>. ?s ?p ?o.} WHERE { ?s ?p ?o. myfoaf:jose foaf:nick "Jo". FILTER ( ! (?s = myfoaf:kendall && ?p = foaf:knows && ?o = myfoaf:edd ) && ! ( ?s = myfoaf:julia && ?p = foaf:mbox && ?o = <mailto:[email protected]> ) && ! ( ?s = myfoaf:julia && ?p = rdf:type && ?o = foaf:Person)) } is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query EncodedQuery default-graph-uri With the response illustrated here: HTTP/1.1 200 OK Date: Fri, 06 May 2005 20:55:11 GMT Server: Apache/1.3.29 (Unix) Connection: close Content-Type: text/turtle
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix foaf: <http://xmlns.com/foaf/0.1/>. @prefix myfoaf: <http://www.example/jose/foaf.rdf#>.
myfoaf:jose foaf:name "Jose Jimeñez"; foaf:depiction <http://www.example/jose/jose.jpg>; foaf:nick "Jo"; ... Note: text/turtle http://www.w3.org/TR/turtle This SPARQL query PREFIX dc: <http://purl.org/dc/elements/1.1/> ASK WHERE { ?book dc:creator "J.K. Rowling"} is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query EncodedQuery default-graph-uri With the response illustrated here: HTTP/1.1 200 OK Date: Fri, 06 May 2005 20:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head></head> <boolean>true</boolean> </sparql> This SPARQL query PREFIX books: <http://www.example/book/> DESCRIBE books:book6 is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query EncodedQuery default-graph-uri With the response illustrated here: HTTP/1.1 200 OK Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/rdf+xml
<?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:books="http://www.example/book/" xmlns:dc="http://purl.org/dc/elements/1.1/" > <rdf:Description rdf:about="http://www.example/book/book6"> <dc:title>Example Book #6 </dc:title> </rdf:Description> </rdf:RDF> This SPARQL query PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?who ?g ?mbox WHERE { ?g dc:publisher ?who . GRAPH ?g { ?x foaf:mbox ?mbox } } is conveyed to the SPARQL query service, http://www.example/sparql/, as illustrated here (with line breaks for legibility): GET /sparql/? query EncodedQuery default-graph-uri default-graph-uri named-graph-uri named-graph-uri named-graph-uri named-graph-uri With the response illustrated here: HTTP/1.1 200 OK Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="who"/> <variable name="g"/> <variable name="mbox"/> </head> ... </sparql> This SPARQL query PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?who ?g ?mbox FROM <http://www.example/publishers> FROM NAMED <http://www.example/alice> FROM NAMED <http://www.example/bob> WHERE { ?g dc:publisher ?who . GRAPH ?g { ?x foaf:mbox ?mbox } } is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query EncodedQuery With the response illustrated here: HTTP/1.1 200 OK Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> ... </sparql> This SPARQL query PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?who ?g ?mbox FROM <http://www.example/publishers> FROM NAMED <http://www.example/john> FROM NAMED <http://www.example/susan> WHERE { ?g dc:publisher ?who . GRAPH ?g { ?x foaf:mbox ?mbox } } is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query EncodedQuery default-graph-uri named-graph-uri named-graph-uri This protocol operation contains an ambiguous RDF Dataset: the dataset specified in the query is different than the one specified in the protocol (by way of default-graph-uri named-graph-uri HTTP/1.1 200 OK Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="who"/> <variable name="g"/> <variable name="mbox"/> </head> <results> <result> <binding name="who"> <literal>Bob Hacker</literal> </binding> <binding name="g"> <uri>http://www.example/bob</uri> </binding> <binding name="mbox"> <uri>mailto:[email protected]</uri> </binding> </result> <result> <binding name="who"> <literal>Alice Hacker</literal> </binding> <binding name="g"> <uri>http://www.example/alice</uri> </binding> <binding name="mbox"> <uri>mailto:[email protected]</uri> </binding> </result> </results> </sparql> This syntactically invalid SPARQL query PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE { ?x foaf:name ?name ORDER BY ?name } is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query EncodedQuery default-graph-uri With the error response illustrated here: HTTP/1.1 400 Bad Request Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: text/plain; charset=UTF-8
4:syntax error, unexpected ORDER, expecting '}' This SPARQL query PREFIX bio: <http://bio.example/schema/#> SELECT ?valence FROM <http://another.example/protein-db.rdf> WHERE { ?x bio:protein ?valence } ORDER BY ?valence is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query EncodedQuery default-graph-uri With the error response illustrated here: HTTP/1.1 500 Internal Server Error Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: text/plain
SPARQL Processing Service: Query Request Refused
Your request could not be processed because http://another.example/protein-db.rdf could not be retrieved within the time alloted. Some SPARQL queries, perhaps machine generated, may be longer than can be reliably conveyed by way of the HTTP GET binding described in 2.1.1 query via GET 2.1.2 query via POST with URL-encoded parameters PREFIX : <http://www.w3.org/2002/12/cal/icaltzd#> PREFIX Chi: <http://www.w3.org/2002/12/cal/test/Chiefs.ics#> PREFIX New: <http://www.w3.org/2002/12/cal/tzd/America/New_York#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?summary WHERE { { Chi:D603E2AC-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-09-08T16:00:00"^^New:tz; :dtstamp "2002-09-06T03:09:27Z"^^xsd:dateTime; :dtstart "2002-09-08T13:00:00"^^New:tz; :summary ?summary; :uid "D603E2AC-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D603E90B-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-09-15T16:00:00"^^New:tz; :dtstamp "2002-09-06T03:10:19Z"^^xsd:dateTime; :dtstart "2002-09-15T13:00:00"^^New:tz; :summary ?summary; :uid "D603E90B-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D603ED6E-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-09-22T16:00:00"^^New:tz; :dtstamp "2002-09-06T03:11:05Z"^^xsd:dateTime; :dtstart "2002-09-22T13:00:00"^^New:tz; :summary ?summary; :uid "D603ED6E-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D603F18C-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-09-29T16:00:00"^^New:tz; :dtstamp "2002-09-06T03:15:46Z"^^xsd:dateTime; :dtstart "2002-09-29T13:00:00"^^New:tz; :summary ?summary; :uid "D603F18C-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D603F5B7-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-11-04"^^xsd:date; :dtstamp "2002-09-06T03:12:53Z"^^xsd:dateTime; :dtstart "2002-11-03"^^xsd:date; :summary ?summary; :uid "D603F5B7-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D603F9D7-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-11-10T20:15:00"^^New:tz; :dtstamp "2002-09-06T03:14:12Z"^^xsd:dateTime; :dtstart "2002-11-10T17:15:00"^^New:tz; :summary ?summary; :uid "D603F9D7-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D604022C-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-11-17T17:00:00"^^New:tz; :dtstamp "2002-09-06T03:14:51Z"^^xsd:dateTime; :dtstart "2002-11-17T14:00:00"^^New:tz; :summary ?summary; :uid "D604022C-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D604065C-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-10-06T19:05:00"^^New:tz; :dtstamp "2002-09-06T03:16:54Z"^^xsd:dateTime; :dtstart "2002-10-06T16:05:00"^^New:tz; :summary ?summary; :uid "D604065C-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6040A7E-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-10-13T19:15:00"^^New:tz; :dtstamp "2002-09-06T03:17:51Z"^^xsd:dateTime; :dtstart "2002-10-13T16:15:00"^^New:tz; :summary ?summary; :uid "D6040A7E-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6040E96-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-10-20T16:00:00"^^New:tz; :dtstamp "2002-09-06T03:18:32Z"^^xsd:dateTime; :dtstart "2002-10-20T13:00:00"^^New:tz; :summary ?summary; :uid "D6040E96-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6041270-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-10-27T17:00:00"^^New:tz; :dtstamp "2002-09-06T03:19:15Z"^^xsd:dateTime; :dtstart "2002-10-27T14:00:00"^^New:tz; :summary ?summary; :uid "D6041270-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6041673-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-11-24T20:05:00"^^New:tz; :dtstamp "2002-09-06T03:22:09Z"^^xsd:dateTime; :dtstart "2002-11-24T17:05:00"^^New:tz; :summary ?summary; :uid "D6041673-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6041A73-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-12-01T17:00:00"^^New:tz; :dtstamp "2002-09-06T03:22:52Z"^^xsd:dateTime; :dtstart "2002-12-01T14:00:00"^^New:tz; :summary ?summary; :uid "D6041A73-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D60421EF-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-12-08T17:00:00"^^New:tz; :dtstamp "2002-09-06T03:24:04Z"^^xsd:dateTime; :dtstart "2002-12-08T14:00:00"^^New:tz; :summary ?summary; :uid "D60421EF-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6042660-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-12-15T20:05:00"^^New:tz; :dtstamp "2002-09-06T03:25:03Z"^^xsd:dateTime; :dtstart "2002-12-15T17:05:00"^^New:tz; :summary ?summary; :uid "D6042660-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6042A93-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-12-22T17:00:00"^^New:tz; :dtstamp "2002-09-06T03:25:47Z"^^xsd:dateTime; :dtstart "2002-12-22T14:00:00"^^New:tz; :summary ?summary; :uid "D6042A93-C1C9-11D6-9446-003065F198AC" . } UNION { Chi:D6042EDF-C1C9-11D6-9446-003065F198AC a :Vevent; :dtend "2002-12-28T21:00:00"^^New:tz; :dtstamp "2002-09-06T03:26:51Z"^^xsd:dateTime; :dtstart "2002-12-28T18:00:00"^^New:tz; :summary ?summary; :uid "D6042EDF-C1C9-11D6-9446-003065F198AC" . } } is conveyed to the SPARQL query service, http://www.example/sparql/ POST /sparql/ HTTP/1.1 Host: www.example User-agent: sparql-client/0.1 Content-Type: application/x-www-form-urlencoded Content-Length: 9461 query EncodedQuery default-graph-uri With the response illustrated here: HTTP/1.1 200 OK Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="summary"/> </head> <results> <result> <binding name="summary"> <literal>Chiefs vs. Cleveland @ Cleveland Stadium</literal> </binding> </result> <result> <binding name="summary"> <literal>Chiefs vs. Jacksonville @ Arrowhead Stadium</literal> </binding> </result> <result> <binding name="summary"> <literal>Chiefs vs. New England @ Gillette Stadium</literal> </binding> </result> ... <result> <binding name="summary"> <literal>Chiefs vs. Oakland @ Network Associates Coliseum</literal> </binding> </result> </results> </sparql> SPARQL queries may also be POSTed directly without URL encoding, as described in 2.1.3 query via POST directly previous example http://www.example/sparql/ POST /sparql/?default-graph-uri=http%3A%2F%2Fanother.example%2Fcalendar.rdf HTTP/1.1 Host: www.example User-agent: sparql-client/0.1 Content-Type: application/sparql-query UnencodedQuery With the same response as in the previous example. SPARQL queries may include internationalized characters or character sets. This SPARQL query PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX 食: <http://www.w3.org/2001/sw/DataAccess/tests/data/i18n/kanji.ttl#> SELECT ?name ?food WHERE { [ foaf:name ?name ; 食:食べる ?food ] . } is conveyed to the SPARQL query service, http://www.example/sparql/ GET /sparql/? query=PREFIX%20foaf%3A%20%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0APREFIX%20%E9%A3%9F%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2Fsw%2FDataAccess%2Ftests%2Fdata%2Fi18n%2Fkanji.ttl%23%3E%0ASELECT%20%3Fname%20%3Ffood%20%0AWHERE%20%7B%20%5B%20foaf%3Aname%20%3Fname%20%3B%20%E9%A3%9F%3A%E9%A3%9F%E3%81%B9%E3%82%8B%20%3Ffood%20%5D%20.%20%7D HTTP/1.1 200 OK Date: Wed, 03 Aug 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) Connection: close Content-Type: application/sparql-results+xml
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> ... </sparql> An example request, which is a serialisation of a request sent to http://localhost:8888/test INSERT DATA { <a> <p> <b> } POST /test HTTP/1.1 Host: localhost:8888 Accept: text/plain Content-Length: 62 Content-Type: application/x-www-form-urlencoded
update=INSERT%20DATA%20%7B%20%3Ca%3E%20%3Cp%3E%20%3Cb%3E%20%7D Update requests may be sent as a POST request with a Content-Type of application/sparql-update POST /test HTTP/1.1 Host: localhost:8888 Accept: */* Content-Type: application/sparql-update Content-Length: 27
INSERT DATA { <a> <p> <b> } A dataset for an update request may be specified using the using-graph-uri using-named-graph-uri http://localhost:8888/test http://localhost:8888/people POST /test?using-graph-uri=http%3A%2F%2Flocalhost%3A8888%2Fpeople HTTP/1.1 Host: localhost:8888 Accept: */* Content-Type: application/sparql-update Content-Length: 136
PREFIX foaf: <http://xmlns.com/foaf/0.1/> DELETE { ?person ?property ?value } WHERE { ?person ?property ?value ; foaf:givenName 'Fred' } A sequence of multiple operations may be included in a single request, separated by a ';' (semicolon). The serialisation of an example request sent to http://localhost:8888/test DELETE DATA { <a> <p> <old> } ; INSERT DATA { <a> <p> <new> } is shown below using the URL-encoded parameter form. POST /test HTTP/1.1 Host: localhost:8888 Accept: */* Content-Type: application/x-www-form-urlencoded Content-Length: 130
update=DELETE%20DATA%20%7B%20%3Ca%3E%20%3Cp%3E%20%3Cold%3E%20%7D%20%3B%0AINSERT%20DATA%20%7B%20%3Ca%3E%20%3Cp%3E%20%3Cnew%3E%20%7D When POSTing an update request with URL-encoded parameters, the dataset parameters using-graph-uri using-named-graph-uri http://localhost:8888/test PREFIX foaf: <http://xmlns.com/foaf/0.1/> INSERT { GRAPH <http://localhost:8888/people> { ?person ?property ?value } } WHERE { GRAPH ?g { ?person ?property ?value ; foaf:givenName 'Fred' } } and specifying a dataset with the named graphs http://localhost:8888/alice/foaf.rdf http://localhost:8888/eve/foaf.rdf POST /test HTTP/1.1 Host: localhost:8888 Accept: */* Content-Type: application/x-www-form-urlencoded Content-Length: 130
using-named-graph-uri=http%3A%2F%2Flocalhost%3A8888%2Falice%2Ffoaf.rdf&using-named-graph-uri=http%3A%2F%2Flocalhost%3A8888%2Feve%2Ffoaf.rdf&update=PREFIX%20foaf%3A%20%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0AINSERT%20%7B%20GRAPH%20%3Chttp%3A%2F%2Flocalhost%3A8888%2Fpeople%3E%20%7B%20%3Fperson%20%3Fproperty%20%3Fvalue%20%7D%20%7D%0AWHERE%20%7B%20GRAPH%20%3Fg%20%7B%20%3Fperson%20%3Fproperty%20%3Fvalue%20%3B%20foaf%3AgivenName%20%27Fred%27%20%7D%20%7D The serialisation of an example request sent to http://localhost:8888/test http://localhost:8888/alice/foaf.rdf http://localhost:8888/eve/foaf.rdf POST /test?using-named-graph-uri=http%3A%2F%2Flocalhost%3A8888%2Falice%2Ffoaf.rdf&using-named-graph-uri=http%3A%2F%2Flocalhost%3A8888%2Feve%2Ffoaf.rdf HTTP/1.1 Host: localhost:8888 Accept: */* Content-Type: application/sparql-update Content-Length: 190
PREFIX foaf: <http://xmlns.com/foaf/0.1/> INSERT { GRAPH <http://localhost:8888/people> { ?person ?property ?value } } WHERE { GRAPH ?g { ?person ?property ?value ; foaf:givenName 'Fred' } } There are at least two possible sources of denial-of-service attacks against SPARQL protocol services. First, under-constrained queries can result in very large numbers of results, which may require large expenditures of computing resources to process, assemble, or return. Another possible source are queries containing very complex — either because of resource size, the number of resources to be retrieved, or a combination of size and number — RDF Dataset descriptions, which the service may be unable to assemble without significant expenditure of resources, including bandwidth, CPU, or secondary storage. In some cases such expenditures may effectively constitute a denial-of-service attack. A SPARQL protocol service may Since a SPARQL protocol service may make HTTP requests of other origin servers on behalf of its clients, it may be used as a vector of attacks against other sites or services. Thus, SPARQL protocol services may effectively act as proxies for third-party clients. Such services may may SPARQL protocol services may may refuse to process such query requests SPARQL protocol services may remove, insert, and change underlying data via the update operation. To protect against malicious or destructive updates, implementations may choose not to implement the update operation. Alternatively, implementations may choose to use HTTP authentication mechanisms or other implementation-defined mechanisms to prevent unauthorized invocations of the update operation. Different IRIs may have the same appearance. Characters in different scripts may look similar (a Cyrillic "о" may appear similar to a Latin "o"). A character followed by combining characters may have the same visual representation as another character (LATIN SMALL LETTER E followed by COMBINING ACUTE ACCENT has the same visual representation as LATIN SMALL LETTER E WITH ACUTE). Users of SPARQL must take care to construct queries with IRIs that match the IRIs in the data. Further information about matching of similar characters can be found in Unicode Security Considerations UNISEC Internationalized Resource Identifiers (IRIs) RFC3987 The status of the parts of SPARQL 1.1 Protocol (this document) is as follows: Section 1 Introduction: normative Section 2 SPARQL Protocol Operations: normative Section 3: Example SPARQL Protocol Requests: informative Section 4: Policy Considerations: normative Section 5: Conformance: normative Section 6: Changes Since Previous Recommendation: informative Section A.1: Normative References: normative Section A.2: Other References: informative A conformant SPARQL Protocol service must query update may query update must RFC2119 4. Policy Considerations This specification extends and updates the SPARQL Protocol for RDF of January, 2008 Remove the WSDL definition of the protocol in favor of an HTTP-based protocol Define an Update operation for issuing SPARQL Update requests Updated conformance criteria to accommodate the update operation Relaxed the requirements on specific HTTP response codes to allow for other codes as long as they align with HTTP semantics Added a variant of the query operation that directly posts a query string in the body of a POST request [SPARQL] SPARQL 1.1 Query Language Latest version [UPDATE] SPARQL 1.1 Update Latest version [RDF-CONCEPTS] Resource Description Framework (RDF): Concepts and Abstract Syntax [RDF-XML] RDF/XML Syntax Specification (Revised) [RFC2119] RFC 2119: Key words for use in RFCs to Indicate Requirement Levels [RFC2616] RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 [RFC3986] RFC 3986: Uniform Resource Identifier (URI): Generic Syntax [RFC3987] RFC 3987: Internationalized Resource Identifiers (IRIs) [UNISEC] Unicode Security Considerations Change Log Changes since Proposed Recommendation None Changes since Candidate Recommendation Fixed typo when referencing the application/x-www-form-urlencoded media type. Changes since Last Call Changed error example to use text/plain instead of text/html.