Skip to content

SPARQL 1.1 Protocol

Andrea Gazzarini edited this page May 17, 2015 · 2 revisions

According with W3C specs [1], the SPARQL Protocol consists of two operations: query and update. Since the SPARQL 1.1 Protocol is built on top of HTTP, each operation is defined in terms of:

  • HTTP method
  • HTTP parameters
  • HTTP Request body
  • HTTP response body

default-graph-uri and named-graph-uri parameters are not yet supported.

Query

The query operation is used to send a SPARQL query to a service and receive the results of the query. SolRDF accepts queries issued in one of the following ways:

Query via GET

When using the GET method, clients must URL percent encode all parameters. The query string can be indicated by means of the "q" or "query" parameter.

curl "http://localhost:8080/solr/store/sparql" \   
--data-urlencode "q=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \   
-H "Accept: application/sparql-results+json"

or

curl "http://localhost:8080/solr/store/sparql" \   
--data-urlencode "query=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \   
-H "Accept: application/sparql-results+json"

Query via URL-encoded POST

When using this method, clients must URL percent encode the "q" or "query" parameter and include within the request body via the application/x-www-form-urlencoded media type. The content type header of the HTTP request must be set to application/x-www-form-urlencoded and the HTTP method is set to POST.

curl -X POST "http://localhost:8080/solr/store/sparql" \   
--data-urlencode "q=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \   
-H "Content-type: application/x-www-form-urlencoded"

Query via POST directly

When using this method, clients send the query directly and unencoded in the HTTP request message body without any parameter. The HTTP method must be POST and the content type header must be set to application/sparql-query.

curl -X POST "http://localhost:8080/solr/store/sparql" \   
--data-binary "SELECT * WHERE { ?s ?p ?o } LIMIT 10" \   
-H "Content-type: application/sparql-query"

Update

The update operation is used to send a SPARQL update request to a service. Differently from the query operation we described below, the update parameter can contain one or more operations, separated by a semicolon. SolRDF accepts updates issued in one of the following ways:

Update via URL-encoded POST

When using this method, clients must URL percent encode the "update" parameter and include within the request body via the application/x-www-form-urlencoded media type. The content type header of the HTTP request must be set to application/x-www-form-urlencoded and the HTTP method is set to POST.

curl -X POST "http://localhost:8080/solr/store/sparql" \   
--data-urlencode "update=INSERT DATA {<a> <b> <x>}" \   
-H "Content-type: application/x-www-form-urlencoded"

Or

curl -X POST "http://localhost:8080/solr/store/sparql" \   
--data-urlencode "update=INSERT DATA {<a> <b> <x>}; DELETE DATA {<c> <d> <e>}" \   
-H "Content-type: application/x-www-form-urlencoded"

Update via POST directly

When using this method, clients send the update command(s) directly and unencoded in the HTTP request message body without any parameter. The HTTP method must be POST and the content type header must be set to application/sparql-update.

curl -X POST "http://localhost:8080/solr/store/sparql" \   
--data-binary "INSERT DATA {<a> <b> <x>}; DELETE DATA {<c> <d> <e>}" \   
-H "Content-type: application/sparql-update"

[1] http://www.w3.org/TR/sparql11-protocol