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

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 un-encoded 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 "q=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \   
-H "Content-type: application/sparql-query"

Update


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