Reputation: 833
I am using Ontotext GraphDB to store semantic data.
GraphDB allows to store/save sparql queries which are exposed as web services.
However I want to store/save sparql queries through HTTP POST request. Below is my query and name of the query will be Query-1
:
let $Query := fn:concat('PREFIX dc: <http://insert/>
INSERT DATA
{
dc:[email protected] dc:played dc:1234 .
}
')
let $EncodeUri := fn:encode-for-uri($Query)
Can anyone help me to write HTTP-POST request command to save this query in GraphDB? I want to use xdmp:http-post()
only.
To get the query result I have used xdmp:http-get('http://localhost:8080//rest/sparql/saved-queries/Query-2')
which works fine.
Upvotes: 0
Views: 1338
Reputation: 3138
It seems you want to make and ingest a Sparql Query through MarkLogic. You may use following code to implement it:
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";
let $Query := 'select * { ?s ?p ?o }'
let $QueryName := 'abcdef'
let $EncodesQuery := fn:encode-for-uri($Query)
let $QData := fn:concat('{
"body": "',$Query,'",
"name": "',$QueryName,'"
}')
return
xdmp:http-post(concat('http://localhost:9080/rest/sparql/saved-queries'),
<options xmlns="xdmp:http">
<data>{$QData}</data>
<headers>
<content-type>application/json</content-type>
</headers>
</options>
)
Upvotes: 1
Reputation: 66
You can execute a POST request to store queries. Following example is using curl:
curl -X POST http://localhost:8080/rest/sparql/saved-queries\
-H 'Content-Type:application/json'\
-d '{
"body": "select * { ?s ?p ?o }",
"name": "Query-2"
}'
You can also find more details about the REST API using GraphDB Workbench (Admin -> REST API Documentation)
Upvotes: 3