I have a SPARQL query in a file called test.rq
. What is a good way of sending a SPARQL request with cURL that uses the query from that file?
(I'm able to perform such a request with a dedicated SPARQL client or by programming the request by using an HTTP library, but I'm assuming quick command-line request, e.g., with cURL should be doable as well.)
There are three standardized ways for sending a SPARQL request:
GET
I tried something like the following, but $(VALUE)
must come from the file test.rq
and it must be URL-encoded.
curl -d 'query=$(VALUE)' $(ENDPOINT)
POST
I tried something like the following, but $(VALUE)
should -- again -- come from file test.rq
, and URL-encoding should be applied.
curl -X POST -d '$(VALUE)' -H 'Content-Type: application/x-www-form-urlencoded' $(ENDPOINT)
POST
This should have worked without URL encoding, doing something like the following.
curl -X POST -d '@query.rq' -H 'Content-Type: application/sparql-query' $(ENDPOINT)
Unfortunately, most SPARQL endpoints do not support this third approach :(
Case 1 from a file:
URL encode the contents of the file and put it in the HTTP URL query string as ?query=
curl --data-urlencode 'query@Q.rq' $(ENDPOINT)