Skip to content

HTTP API ​

SPARQL endpoint ​

GET|POST <path> (default /sparql) implements the query operation of the SPARQL 1.1 Protocol:

RequestQuery from
GET /sparql?query=…the query parameter
POST /sparql with Content-Type: application/x-www-form-urlencodedthe query form field
POST /sparql with Content-Type: application/sparql-querythe body

default-graph-uri and named-graph-uri parameters (in the URL, or in the form body) are supported and replace the query's FROM / FROM NAMED, as the protocol specifies. They are intersected with the granted graphs like FROM clauses.

Credentials ​

Authorization: Bearer <key>, X-API-Key: <key>, or the trusted headers. See Authentication.

Response ​

The store's response is streamed back with its status code and Content-Type. The Accept header is passed on. If the client sends none (or */*), sparql-guard asks for application/sparql-results+json for SELECT and ASK, and text/turtle for CONSTRUCT and DESCRIBE.

Status codes ​

StatusMeaning
200Answered by the store.
400The query cannot be parsed or cannot be rewritten safely; also a missing query.
401Missing or invalid credentials.
403No policy applies, or the query uses something that is not allowed (updates, SERVICE, hidden paths).
404Unknown path.
405Method other than GET, POST, OPTIONS.
413Request body larger than 1 MiB.
415Unsupported Content-Type for POST.
502The store could not be reached or timed out.
otherPassed through from the store.

Error responses from sparql-guard are text/plain with a one-line message.

Updates ​

Requests with Content-Type: application/sparql-update, an update parameter, or an update operation in the query are refused with 403 before anything is sent to the store.

CORS ​

Responses allow the requesting origin, with the Authorization, Content-Type, Accept and X-API-Key headers, so browser-based clients such as Yasgui can call the endpoint directly. OPTIONS preflight requests are answered with 204.

Explain ​

GET|POST <path>/explain takes exactly the same requests as the SPARQL endpoint, but returns the rewritten query instead of executing it. It is only available with "explain": true.

sh
curl -H 'Authorization: Bearer jan-key' \
  --data-urlencode 'query=SELECT * WHERE { ?s a <https://example.org/rail/vocab#WorkOrder> }' \
  http://localhost:8095/sparql/explain
json
{
  "agent": "urn:sparql-guard:user:jan",
  "groups": ["maintenance-north"],
  "policies": [
    "<https://example.org/rail/policy/public>",
    "<https://example.org/rail/policy/maintenance-north>"
  ],
  "query": "SELECT ?s FROM <https://example.org/rail/graph/network> … WHERE { … }",
  "form": "select"
}

Explain applies the same authentication and policies, and returns the same errors, as the endpoint itself.

Health ​

GET /healthz returns 200 ok. It needs no credentials and does not contact the store.

Released under the Apache-2.0 license.