Overview

This describes how to create, retrieve, update and delete RDF content. 

Many resources in Callimachus are defined solely by RDF statements. These include folders, users, groups and concepts, but not bulk RDF instance data (see the section CRUD Operations on BLOB Content for those). See Appendix for supported RDF resource types.

Operations

Create

RDF resources are created by performing an HTTP POST to the URL enclosing folder's describedby URL with a Content-Type ofapplication/sparql-update and a body of a SPARQL INSERT DATA command. The response will include a Location: header with the URL of the resource created. The RDF data needs to include a supported rdf:type (see Appendix for details). This approach may only be used to insert one resource at a time (a single identified RDF Subject; additional resources may be inserted if they are blank nodes or hash URIs off of the identified Subject).

As a reminder, the enclosing folder's describedby URL may be found via its Atom feed (where the attribute rel=="describedby"). See the Browsing Content section for more details.

If you wanted to make a folder called "test" at the top level, first create a file with the appropriate SPARQL INSERT DATA query. We'll save this file with a name of "testcreate.ru":

BASE <http://example.com:8080/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX calli: <http://callimachusproject.org/rdf/2009/framework#>

INSERT DATA {
    <test/> a calli:Folder, </callimachus/Folder> ;
        rdfs:label "test" .
}

The HTTP POST looks like this:

POST http://example.com:8080/#rel=describedby HTTP/1.1
Content-Type: application/sparql-update
Authorization: Digest username="john", realm="http://example.com:8080/", ...

BASE <http://example.com:8080/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX calli: <http://callimachusproject.org/rdf/2009/framework#>

INSERT DATA {
    <test/> a calli:Folder, </callimachus/Folder> ;
        rdfs:label "test" .
}

The equivalent curl command is:

curl --digest --user john --data-binary @testcreate.ru -H "Content-Type: application/sparql-update" \
  "http://example.com:8080/#rel=describedby"

Normal HTTP response codes are used to indicate success or failure of the request:

HTTP/1.1 201 Created
Location:  http://example.com:8080/test/

Retrieve

Performing an HTTP OPTIONS on an RDF resource's created URI returns a link: header with rel=”decribedby” and the resource's DescribedBy URL. Performing an HTTP GET on the DescribedBy URL with an Accept: header of text/turtle or application/rdf+xml will return an RDF representation of the resource.

For a folder called "/test":

OPTIONS http://example.com:8080/test/ HTTP/1.1

The equivalent curl command is:

curl -I -X OPTIONS http://example.com:8080/test/

Results would look like:

HTTP/1.1 204 No Content
Link: <http://example.com:8080/test/#rel=version-history>; rel="version-history"; type="application/atom+xml;q=0.5 text/html"
Link: <http://example.com:8080/test/#rel=describedby>; rel="describedby"; type="text/html"; title="RDF Describe"
Link: <http://example.com:8080/test/#rel=contents>; rel="contents"; type="application/atom+xml;q=0.5"
Link: <http://example.com:8080/test/#rel=alternate&type=html>; rel="alternate"; type="text/html"
Link: <http://example.com:8080/test/#rel=..archive>; rel="http://callimachusproject.org/rdf/2009/framework#archive"
Link: <http://example.com:8080/test/#rel=alternate&type=atom>; rel="alternate"; type="text/html application/atom+xml;q=0.5"

Performing an HTTP GET on the DescribedBy URL returns the RDF. In this case, the Turtle format is requested. The result would be a Turtle document with the triples used in the Create section, above.

GET http://example.com:8080/test/#rel=describedby HTTP/1.1
Accept: text/turtle

The equivalent curl command is:

curl -H "Accept: text/turtle" "http://example.com:8080/test/#rel=describedby"

Normal HTTP response codes are used to indicate success or failure of the request.

Update

Performing an HTTP OPTIONS on an RDF resource's created URI returns a link: header with rel=”decribedby” and the resource's describedby URL. See also the discussion regarding HTTP 303 responses from a created URI in the Retrieve section, above. Performing an HTTP PATCH on the describedby URL with an Content-Type: header of application/sparql-update and a body of a SPARQL DELETE INSERT will update the resource.

NB: Updating a Folder, User, Group etc, has the potential to negatively impact internal Callimachus state: Be Careful!

To update the RDF definition of the "/test/" folder, first create a SPARQL DELETE INSERT query and put it into a file (in this case we'll call the file "testupdate.ru"). The contents of the file might look like this:

BASE <http://example.com:8080/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
​DELETE {
        </test/> rdfs:label ?label .
}
INSERT {
        </test/> rdfs:label "Test Folder" .
}
WHERE {
        </test/> rdfs:label ?label .
}

The HTTP command is then:

PATCH http://example.com:8080/test/#rel=describedby HTTP/1.1
Content-Type: application/sparql-update
Authorization: Digest username="john", realm="http://example.com:8080/", ...

BASE <http://example.com:8080/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

DELETE {
        </test/> rdfs:label ?label .
}
INSERT {
        </test/> rdfs:label "Test Folder" .
}
WHERE {
        </test/> rdfs:label ?label .
}

The equivalent curl command is:

curl --digest --user john -X PATCH --data-binary @testupdate.ru -H "Content-Type: application/sparql-update" \
  "http://example.com:8080/test/#rel=describedby"

Normal HTTP response codes are used to indicate success or failure of the request:

HTTP/1.1 204 No Content
Server: Callimachus Server/Callimachus 0.1
...

Delete

Performing an HTTP OPTIONS on an RDF resource's created URI returns a link: header with rel=”decribedby” and the resource's describedby URL. See also the discussion regarding HTTP 303 responses from a created URI in the Retrieve section, above. Performing an HTTP DELETE on the DescribedBy URL will delete the resource.

To delete the "/test/" folder:

DELETE http://example.com:8080/test/#rel=describedby HTTP/1.1
Authorization: Digest username="john", realm="http://example.com:8080/", ...

The equivalent curl command is:

curl --digest --user john -I -X DELETE "http://example.com:8080/test/#rel=describedby"

Normal HTTP response codes are used to indicate success or failure of the request. In this case, a successful delete is indicated by a 200 (OK) or 204 (No Content) response.