I am having an issue trying to make a request to the SPARQL query route /{db}/query
with multiple Accept mime types.
There is no single Accept mime type on the SPARQL query route which works for all query types, and so it is convenient for me to specify multiple Accept mime types on the request. The reason for this is that I do not necessarily know the SPARQL query type being passed to the route. I chose 3 different Accept mime types for the following query types:
- CONSTRUCT / DESCRIBE: application/n-quads,
- SELECT: text/csv,
- ASK: text/boolean
Format 1
curl --location --request GET '{host}/{db}/query?query={urlEncodedQuery}' \
--header 'Accept: application/n-quads' \
--header 'Accept: text/csv' \
--header 'Accept: text/boolean'
Tests
- CONSTRUCT Query
CONSTRUCT {GRAPH ?g {?s ?p ?o}} WHERE {GRAPH ?g {?s ?p ?o}}
- Sends back expected result
- SELECT Query
SELECT ?s ?p ?o ?g WHERE {GRAPH ?g {?s ?p ?o}}
- Sends back expected result
- ASK Query
ASK WHERE {GRAPH ?g {?s ?p ?o}}
-
Error:
text/csv is not a known mime type for the results of a query
Format 2
curl --location --request GET '{host}/{db}/query?query={urlEncodedQuery}' \
--header 'Accept: application/n-quads' \
--header 'Accept: text/boolean' \
--header 'Accept: text/csv'
- Switched
--header 'Accept: text/boolean'
with--header 'Accept: text/csv'
Tests
- CONSTRUCT Query
CONSTRUCT {GRAPH ?g {?s ?p ?o}} WHERE {GRAPH ?g {?s ?p ?o}}
- Sends back expected result
- SELECT Query
SELECT ?s ?p ?o ?g WHERE {GRAPH ?g {?s ?p ?o}}
-
Error:
text/boolean is not a known mime type for the results of a query
- ASK Query
ASK WHERE {GRAPH ?g {?s ?p ?o}}
- Sends back expected result
The order of the Accept mime types matters only for ASK and SELECT. No matter where you put the --header 'Accept: application/n-quads'
declaration, the CONSTRUCT query will always return the expected result.