Socialwg/Social API/LDP

From W3C Wiki

Overview

The Linked Data Platform Working Group is publishing a set of specifications [listed on their main wiki page. The Linked Data Platform 1.0 specification is currently ( December 2014 ) in Last Call. A number of other documents can be found on the wiki including the LDP-Primer that gives an introductory overview and the test compliance reports for 9 known implementations.

Linked Data requires a mode of interaction that requires one to take into account that by following links a client can end up on any server. The interaction MUST therefore be specified in such a way that the client can by just looking at the resource in question understand how to interact with it with minimal context, as well as allowing data resources to work seamlessly with it.

Overview of Crud Features

A good set of examples can be found in the LDP Primer. Here the examples using curl are taken from rww-play curl interaction page.

Read: GET

$ curl -k -i -X GET  https://localhost:8443/2013/
HTTP/1.1 200 OK
Link: <https://localhost:8443/2013/.acl>; rel=acl
Content-Type: text/turtle
Content-Length: 201


<> <http://xmlns.com/foaf/0.1/maker> <http://bblfish.net/people/henry/card#me> ;
    <http://www.w3.org/ns/ldp#created> <card> , <test/> , <couch> .

Content-negotation allows one to return JSON-LD.

( Note: It may be interesting here to use a vocabulary specified by the Social Web WG to describe the resources )

$ curl -i -H "Accept: application/ld+json" -k https://localhost:8443/2013/card
HTTP/1.1 200 OK
Accept-Patch: application/sparql-update
Access-Control-Allow-Origin: *
Allow: OPTIONS, GET, HEAD, SEARCH
Content-Type: application/ld+json
ETag: "1417390950000|Success(922)"
Last-Modified: Sun, 30 Nov 2014 23:42:30 GMT
Link: <http://www.w3.org/ns/ldp#Resource>; rel=type, <card.acl>; rel=acl
Content-Length: 1245

{
  "@graph" : [ {
    "@id" : "#me",
    "@type" : "http://xmlns.com/foaf/0.1/Person",
    "http://www.w3.org/ns/auth/cert#key" : {
      "@id" : "_:node1981hgchsx1"
    },
    "http://xmlns.com/foaf/0.1/knows" : {
      "@id" : "http://bblfish.net/people/henry/card#me"
    },
    "http://xmlns.com/foaf/0.1/name" : "Me (StampleIO test webid)"
  }, {
    "@id" : "_:node1981hgchsx1",
    "@type" : "http://www.w3.org/ns/auth/cert#RSAPublicKey",
    "http://www.w3.org/ns/auth/cert#exponent" : {
      "@type" : "http://www.w3.org/2001/XMLSchema#integer",
      "@value" : "65537"
    },
    "http://www.w3.org/ns/auth/cert#modulus" : {
      "@type" : "http://www.w3.org/2001/XMLSchema#hexBinary",
      "@value" : "b7cb16af0aeec58a4c0c05e0504a334382a1db7a8a092057f97c271439f7ff8cfd469b615934fa401b4b320b756cf017e16c8ee0d5afceed1a54390738720c67813b765e1bf9e310809e133b7f7c2aca34e185c3bdcd42fc40d84772ad691f36b9078c8e0079f64089ae0adcaa80d4186cf683403d6485e578dbde161a82b4e34650cb77fd274fe84bb7ae488a3236f146178cf836cc701b1d3c40c0d7a8e838afc209e3b5c825fa9702017b52492f4cf4bdeb089726e2778eb63b8854c8b366b2c5425f5dec236c02c8e760b7303adfb2a94bf835c2e28901abeca292d7ca04c1ae3c377e2d2f3e011be76868d941678a18c2abf78f98f796f493f2a946cf2d"
    }
  } ]
}

Create: POST

On creates by POSTing to an LDP Container.

There are any number of ways of authenticating. One way to do it is to use a client certificate, which would allow one to authenticate on any web server, as the client follows links. This is used below. But other authentication schemes would be fine too. See LDP-next.

Data Resources

It is possible to create data resources in Turtle format or in JSon-LD format

$ curl -X POST -k -i -H "Content-Type: text/turtle; utf-8"  \
    --cert ../eg/test-localhost.pem:test  \
    -H "Slug: couch" -d @../eg/couch.ttl https://localhost:8443/2013/  \
HTTP/1.1 201 Created
Location: https://localhost:8443/2013/couch
Content-Length: 0
$ curl -X POST -k -i -H "Content-Type: applicstion/ld+json"  \
    --cert ../eg/test-localhost.pem:test  \
    -H "Slug: couch" -d @../eg/couch.ttl https://localhost:8443/2013/  \
HTTP/1.1 201 Created
Location: https://localhost:8443/2013/couch
Content-Length: 0

Binary Resources

LDP allows the posting of any form of binary resource, be it document, picture, video, code (JS, CSS), etc...

$ curl -X POST -k -i -H "Content-Type: image/png" \
   --cert ../eg/test-localhost.pem:test \
   -H "Slug: Apache-feather" 
   --data-binary @../eg/apache-feather.png 
   https://localhost:8443/2013/ 

DELETE

$ curl -k -i -X DELETE \
   --cert ../eg/test-localhost.pem:test https://localhost:8443/2013/couch
HTTP/1.1 200 OK
Content-Length: 0

Update

PUT

replace a resource in its entirety.

PATCH

Is like PUT but allows to be more precise

Using SPARQL Update
$ cat ../eg/card.update
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
DELETE DATA { <https://localhost:8443/2013/card#me> foaf:name "Me (StampleIO test webid)" . };

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
INSERT DATA { <https://localhost:8443/2013/card#me> foaf:name "Henry Story" . }
$ curl -X PATCH -k -i --data-binary @../eg/card.update \
    -H "Content-Type: application/sparql-update; utf-8" \
    -H 'If-Match: "1417390950000|Success(922)"'  \
    --cert ../eg/test-localhost.pem:test  \
    https://localhost:8443/2013/card
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
User: https://localhost:8443/2013/card#me
Content-Length: 9

Succeeded
Using LDP Patch

Because PATCH is an HTTP verb different formats are allowed. A new simpler to implement format LDP Patch is being developed.

LDP Next

The LDP group is considering continuing its work where it will be able to focus on

( potentially something along the lines of WebID & Web Access Control

  • Querying:
    • potentially a QUERY/SEARCH verb ( as in WebDAV )
    • integration with SPARQL
    • potentially development of a less powerful but simpler to implement query language
  • data shapes

see LDP Next wish list

Example use case: Simple notification

A very important social web use case is notification. How can I follow links across the web and know when I reach a resource how to send a notification to the owner. A very simple way of doing this would be to create a ping relation such as described below to an ldp Container or Indirect Container.