Although this post uses Dydra graph database cloud service to illustrate the concepts, the approach is equally applicable to any RDF graph store that supports the SPARQL 1.1 Graph Store HTTP Protocol
Loading data to Dydra is pretty simple from the UI or with SPARQL 1.1 Update, however it can sometimes be easier to implement or work with HTTP operations at named graph level (where a named graph can be thought of as an RDF ‘document’).
To enable this Dydra supports the HTTP
POST methods as defined by the SPARQL 1.1 Graph Store HTTP Protocol recommendation.
The graph store service endpoint of a repository is the repository URI followed by
To access the default graph, simply add
?default parameter. To access a specific named graph use
?graph parameter with the percent-encoded IRI of the named graph as the value (Dydra uses the indirect graph identification approach). For example to work with the graph
http://example.com/mygraph use parameter
?graph=http%3A%2F%2Fwww.example.com%2Fmygraph (you can easily percent encode the graph IRI using online tools such as the URL Decoder/Encoder).
If the Dydra repository has privacy settings applied, you will also need to authenticate using basic HTTP authentication in conjunction with your API key e.g.:
The HTTP methods behave as follows:
GETfetches a serialization of the specified graph. The default format is Turtle, but other formats can be requested via content negotiation using the
PUTstores the RDF payload in the specified graph. Any existing data in the graph is overwritten. The format of the supplied RDF is specified using the
DELETEremoves the specified graph from the repository. If the default graph is specified, it is equivalent to
DROP DEFAULTin SPARQL 1.1 Update
POSTappends the RDF payload to the specified graph. Any existing data in the graph is retained (an RDF merge of the graphs is performed). Again the format of the supplied RDF is specified using the
nlv01111/gsprepository in (default) Turtle serialization format:
nlv01111/gsprepository in JSON-LD format and output to local file
>curl -H "Accept: application/ld+json" "http://dydra.com/nlv01111/gsp/service?graph=http%3A%2F%2Fexample.com%2Fmygraph" -o data.jsonld
data.ttlto the default graph in the
>curl -v -X PUT --data-binary @data.ttl -H "Content-Type: text/turtle" "http://dydra.com/nlv01111/gsp/service?default&auth_token=MY_API_KEY"
data.rdfto the named graph
>curl -v -X PUT --data-binary @data.rdf -H "Content-Type: application/rdf+xml" "http://dydra.com/nlv01111/gsp/service?graph=http%3A%2F%2Fexample.com%2Fid%2Fmygraph&auth_token=MY_API_KEY"