This primer provides an introduction to the Linked Data Platform (LDP), with examples illustrating the principal concepts such as the notion of an LDP resource and the LDP container and how they can be used by Web clients. Two sample scenarios show how an LDP client can interact with a LDP server in the context of a read-write Linked Data application i.e. how to use HTTP for accessing, updating, creating and deleting resources from servers that expose their resources as Linked Data.

This is the first draft of LDP Primer Note from the W3C LDP working group.

Introduction

The term "Linked Data" [[LINKED-DATA]] refers to an approach to publishing data that puts linking at the heart of the notion of data, and uses the linking technologies provided by the Web to enable the weaving of a global distributed database. By naming real world entities - be they web resources, physical objects such as the Eiffel Tower, or even more abstract things such as relations or concepts - with http(s) URLs, whose meaning can be determined by dereferencing the document at that URL, and by using the relational framework provided by RDF, data can be published and linked in the same way web pages can. The Linked Data Protocol specifies how web applications can, using the HTTP protocol, find resources and follow links, publish new resources, edit and delete existing ones.

The Primer aims to provide introductory examples and guidance in the use of the LDP protocol, in accordance with best practices [[LDP-BP]]. For a systematic description of the protocol the reader should consult the normative LDP reference [[LDP]]. For an overview of the use cases for LDP and the elicited requirements that guided its design, the reader should consult the LDP Use Cases and Requirements [[LDP-UCR]]; for best practices and guidelines, the reader should consult the LDP Best Practices and Guidelines document [[LDP-BP]].

Conventions Used in This Document

The examples in this guide are given as a serialization of RDF graphs using the Turtle [[turtle]] and JSON-LD [[json-ld]] syntaxes of RDF.

The buttons below can be used to show or hide the available syntaxes.

The JSON-LD examples refer to the following (external) context document:

 
      { 
       "@context":
       {
         "rdf":     "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
         "rdfs":    "http://www.w3.org/2000/01/rdf-schema#",
         "owl":     "http://www.w3.org/2002/07/owl#",
         "ldp":     "http://www.w3.org/ns/ldp#",
         "xsd":     "http://www.w3.org/2001/XMLSchema#",
         "dcterms": "http://purl.org/dc/terms/",
         "foaf":    "http://xmlns.com/foaf/0.1/",
         "wdrs":    "http://www.w3.org/2007/05/powder-s#",
         "bt":      "http://example.org/vocab/bugtracker#"
       }  
      }
  

LDP concepts in a glance

A server hosting Linked Data Platform Resources (LDPRs) may manage two kinds of LDPRs: those resources whose state is represented using RDF (called LDP RDF Sources (LDP-RSs)), and those using other formats (called LDP Non-RDF Sources (LDP-NRs)) such as HTML files, images, other binary files, etc. Resoures respond to retrieval operations using HTTP GET. Often a description conveyed in the response document will describe a specific domain entity; Status, Friendship, Product, Order, Bug, etc. On the other hand, it might contain a description of a number of different concepts. The links contained in the descriptions lead to the subsequent discovery and processing of other resources. Affordances offered by the server make discoverable the forward paths in the application. Together the resources, links and associated affordances together specify what might be termed the API.

Types of LDPRs:

The LDP protocol covers read and write interactions with Resources. Writable aspects include creation of new resources (using POST or PUT), updates (using PUT or PATCH), and deletion of resources. Resource creation is an essential feature providing structured creation of resources. Affordances published by the server show that some Resources can be used to create other Resources. This common pattern is often seen in cases where one resource is be made up of a number of others, e.g. a Document Store consists of Documents, a Bug Tracker consists of Bug Reports, a Photo Album consists of Photos, the Net Worth of a person consists of Assets and Liabilities. LDP defines creation for a special kind of Resource called a Container (LDPC), which is able to respond to requests to create new resources, in addition to the general mechanisms HTTP defines. During creation the created resource is added to its Container and a containment link between the Container and the new entry is made.

Therefore a LDPC is a specialization of a LDP-RS representing a collection of links to LDPRs or information resources [[WEBARCH]] that responds to client requests for creation, modification, and/or enumeration of its linked members and documents. The simplest container is the Basic Container (LDP-BC). It defines the basic containment described using a generic vocabulary. This can be used in a generic storage service to manage a containment hierarchy of arbitrary resources.

..
Generic document storage using a Basic Container.

Such servers do not impose any restriction on LDPRs and generally act as storage systems without any domain specific application logic and vocabularies. The first scenario in this document concerns a document storage system based on Basic Containers.

A Direct Container is a specialisation of a Basic Container. Additional assertions called membership triples which use a domain-specific vocabulary are made by a Direct Container as part of the creation process. The membership triples augment the containment triples maintained by all containers. For example, one aspect of a Product inventory system concerns the how a Direct Container is used for the management of a Product portfolio, where use of existing vocabularly is preferable.

..
Using domain vocabularly with a Direct container.

Direct Container membership triples can be about subjects other than the Container resource. An example is a Photo management application where a Photo Container is used for the management of Photos, and where membership triples then express the relationship between a User and a Photo.

..
Membership triples with a non-Container subject.

Another common pattern is where different facets of a Resource be managed using multiple Containers. For example, a Bug Report is has an associated list of Comments as well as supportive media resources.

..
Managing multiple facets of a Bug with two Direct Containers.

One important usage concerns using LDP to expose the data and services of existing applications. These systems impose restrictions on LDPRs since the LDP interactions should consider the constraints of the underlying business logic and data model. The bug tracker example presented in the latter part of this primer is an example of an application specific LDP server.

Formal definitions of the terms LDPR, LDPC, and other concepts introduced by LDP can be found in the 'Terminology' section of the Linked Data Platform 1.0 specification [[LDP]]

The following provide a set of examples to show the Linked Data Platform interactions. Note, this is a primer and should not be considered as a canonical example of ideal LDP modeling.

Online document store example (LDP Basics)

This section provides a set of examples of using an online document store application. These examples will demonstrate the behaviour of both types of LDPRs and LDP Basic Containers. Registration with the online document store application by a user results in some data storage space (a root Basic Container) where the application's web resources are stored. Using this root Basic Container a user can create new documents and also child containers to further organize her documents stored in this application.

APIs of web applications are commonly documented by listing valid operations which can operate on URLs, where the URLs are described as templates. A description of our exemplary LDP based document store is in the following table. We note with emphasis that it is important for servers to use links as the main mechanism to reveal the location of resources. If it would be necessary to encode such templates into client applications, this would be a strong indicator that the design breaches a number of good design principles.

Path Method Description
/{username}/ GET Lists all the documents in the root container.
POST Create a new document under the root container.
PUT Update the description and/or list of files of the root container.
PATCH Update the description and/or list of files of the root container.
DELETE Not allowed.
/{username}/{{document}/}*
GET Retrieve the document.
POST Discovered from the resource affordances.
PUT Update the document.
PATCH Partial update to the document if PATCH is supported.
DELETE Delete the document.
/*/*
OPTIONS Discover the allowed operations over a resource
HEAD Only retrieve meta-information about a resource

In this example, we will see how Alice, a user of this system, does read / write management of documents using the LDP protocol. A typical interaction with the system would start with Alice registering as a user. It is likely that registration would be a LDP based interaction, but this aspect is out of scope of this example. A consequence of the registration is allocation of space for the storage of documents, and communication of this URL to the user, e.g. a basic container at http://example.org/alice/. This section describes a typical flow of interactions where Alice firsts reads the root document and discovers its affordances. This is followed by subsequent examples of creation, update and delete, and finishes with how the client is able to create nested structure from the containers.

Looking up a basic container (GET on an LDP-BC)

First Alice looks up her storage by retrieving the LDP Basic Container assigned to her to hold her documents. Alice's LDP client does this by doing a GET request on the URI, http://example.org/alice/.

 
      
      

As her document storage was just created, it is an empty container.

 
      
      

As shown in the example, in addition to the RDF representation of the Basic Container using the requested media type the server provides an etag of the resource representation and Link headers advertising that the requested resource is indeed an LDP Basic Container and it will support the LDP interaction model.

In addition, the response also contains "Allow" header which advertises which HTTP operations are supported by this LDP Basic Container resource. In this example, it supports OPTIONS,HEAD,GET,POST,PUT,PATCH HTTP verbs.

The Linked Data Platform 1.0 specification [[LDP]] says that all LDP servers MUST support the Turtle media type for LDP-RS resources and SHOULD support JSON-LD media type.

Discovering the affordances (OPTIONS on an LDP-BC)

In the previous example, we saw that Alice can discover what operations are allowed on a resource by doing a GET request on the resource. As an alternative, she can use the OPTIONS operation to learn of the permitted operations on any given resource.

 OPTIONS /alice/ HTTP/1.1
 Host: example.org      
      
HTTP/1.1 204 OK
Allow: OPTIONS,HEAD,GET,POST,PUT,PATCH
Accept-Post: text/turtle, application/ld+json, image/bmp, image/jpeg
Accept-Patch: example/patch
Link: <http://www.w3.org/ns/ldp#BasicContainer>; rel='type'     
      

According to the response, HTTP operations {OPTIONS,HEAD, GET,POST,PUT,PATCH} are allowed on her root container. In addition to the allowed operations, Accept-Post and Accept-Patch provides which media types are supported by the respective operations. The rel="type" Link header advertises that this resource supports LDP protocol and it is an LDP Basic Container.

In this case, the response tells Alice's LDP client that this is an LDP-Basic Container and the container allows her to POST things of both RDF types (text/turtle, application/ld+json) and images (image/bmp and image/jpeg).

Creating a RDF resource (POST an RDF resource to an LDP-BC)

Alice can upload a social profile document to her store, by POSTing her FOAF personal profile document to her LDP-BC at the root of her document store. Note, the Slug header offers the server a hint about URL of the resource to be created.

The FOAF document includes statements about the resource to be created and other resources relative to the resource to be created. According the LDP specification Alice can use null relative URI (<>) in the request entity body to refer to resource to be created.

 

    

   
 
HTTP/1.1 201 Created
Location: http://example.org/alice/foaf
Link: <http://www.w3.org/ns/ldp#Resource>; rel='type'
Content-Length: 0 
   

The response to the create request provides a Link to the newly created resource using the Location header. In this case, the server has honored the hint provided by the slug header and created the new resource in the URL http://example.org/alice/foaf.

Knowing the URL of the newly created resource, Alice can check the container again to confirm that the container correctly contains the newly created resource.

    GET /alice/ HTTP/1.1
    Host: example.org
    Accept: text/turtle, application/ld+json
     
     

The ldp:contains containment triple discloses the newly created resource in the response.

Creating a non-RDF (binary) resource (POST an image to an LDP-BC)

Next, Alice wants to upload a photo of herself to the document storage. She can create an image by POSTing it in the same way she created the RDF document.

 
POST /alice/ HTTP/1.1
Host: example.org
Slug: avatar
Link: <http://www.w3.org/ns/ldp#Resource>; rel="type"
Content-Type: image/png
Content- Length: 1020

### binary data ###
   
 
HTTP/1.1 201 Created
Location: http://example.org/alice/avatar
Link: <http://www.w3.org/ns/ldp#Resource>; rel="type"
Link: <http://example.org/alice/avatar/meta>; rel="describedby"
Content-Length: 0   
   

The outcome of creating a non-RDF is similar to creating a RDF resource. If successful, the server will return a 201 success code with a Location header that points to the created resource. Furthermore, in the case of binary resources the server may create an additional file to maintain the metadata about the binary file. In the above example, the server creates a new LDP-RS to maintain metadata about the binary resource such as creation date, owner, etc. and this metadata resource is advertised using a Link header with the relation "describedby".

Similar to creating a RDF resource (LDP-RS), a containment triple will be added to the container when a non-RDF (LDP-NR) is created. Thus, the representation of the LDP container after creating the image looks like the following.

 
    

Update a RDF LDP resource (PUT on an LDP-RS)

After creating the image as shown in the previous example, Alice now wants to update her FOAF profile with a link to the image. After retrieving her FOAF profile using a HTTP GET operation, she uses HTTP PUT to update the document by amending the RDF with a link to her photo.

In this example, Alice's LDP client sends the E-tag of the resource representation that it retrieved previously to prevent any lost update problems.

 

      
 
HTTP/1.1 204 No Content 
Link: <http://www.w3.org/ns/ldp#Resource>; rel="type" 
      

If the operation is successful as shown above, the document will be updated with new information.

Alice can also use the PATCH operation to update the resource.

Deleting a resource (DELETE on an LDPR)

If Alice decides to delete the image, she can do that with a delete operation.

Similar to the previous update operation, Alice uses the etag of the resource representation she retrieved with If-Match header to do a conditional delete to ensure that the resource state was not changed since she decided to delete it.

 
DELETE /alice/avatar HTTP/1.1
Host: example.org
If-Match: W/"123454322"        
   
 
HTTP/1.1 204 No Content 
   

As well as deleting the resource, the server removes the containment triple from the container. For example, a subsequent GET request on the container will return a graph isomorphic to the one shown in the following representation::

 
     
     

For any subsequent request on the deleted resource, the server will respond with the appropriate HTTP response code.

    GET /alice/avatar HTTP/1.1
    Host: example.org
    Accept: image/png
     
 
HTTP/1.1 410 Gone 
   

Structural Manipulation (Child Containers)

In order for the client to introduce hierarchy to the management of documents, the document store allows creation of documents which are containers. That enables Alice to create a container hierarchy to organise her documents. This can be done by POSTing (a child) container representation to a (parent) container. This enables Alice to create a child container which she intends to use for image storage.

..
Child Containers inside a Basic Container.
  

      

To create a new container for managing photos, Alice POSTs a representation of a container (LDP-BC) to the root container. Alice express her intention that the newly created resource should be an LDP Basic Container by including a Link header in the request with the relationship 'type'.

  
      

If the create is successful, the server responds with location of the newly created container for the photos.

HTTP/1.1 201 Created
Location: http://example.org/alice/photos/
Content-Length: 0  
        

After creation of this new container, the parent container will look like

 
      

and the photo container will look like the following.

 

    

Bug Tracker Example (LDP Direct containers)

The previous section provided practical examples of basic LDP interactions using LDP Basic Containers. One of the limitations of LDP Basic Containers is that a fixed LDP vocabulary is used to assert the relations between a container and its contained resources. However, some scenarios require domain specific vocabulary to be used to list the members of a container. For example, an application which already used Linked Data and its own vocabulary may like to continue using the same vocabulary when migrating to LDP protocol. LDP Direct containers introduce the concept of membership triples allowing the flexibility to define the form of the membership. One of these flexibility points is the ability to select the predicate of the membership triple which can be from a domain-specific vocabulary. This is done using the ldp:hasMemberRelation or ldp:isMemberOfRelation predicate of the Direct Containers.

In addition, in some scenarios it is necessary to add relationships between the newly created resource and some other resource (which is not necessarily the container or another document / information resource). This allows to define relationship between any other information resource or non-information resource (real world thing) by defining the membership constant subject or the object URI of the membership triples using ldp:membershipResource predicate of the Direct Container. The usage of the ldp:hasMemberRelation predicate as well as the ldp:membershipResource will be explained in the following examples.

For more information on information resources (documents) vs real world entities (things) separation please refer to Web Arch (Section 2.2. URI/Resource Relationships) , , Cool URIs (Section 3. URIs for Real-World Objects), URLs in Data (Section 3. Landing Pages and Records).

The examples in this section will revolve around a very simple Bug Tracker application. Bug Tracker application records the bugs of several products allowing reporting, updating and deleting bugs and products. In contrast to the online document store example, the bug tracker wants to use an existing domain vocabulary, e.g. has_bug, to express membership relationships in the containers. LDP provides the additional interaction capability in the protocol to add the domain specific triples based on the properties defined in the LDP Direct Container.

A RESTful API for a simple Bug Tracker system might be described as follows.

Path Method Description
/tracker/{product-id}/
GET Lists the product description and bug reports associated with a product.
POST Create a new bug report associated with a product.
PUT Update the project description.
PATCH Not supported.
DELETE Delete the project description and associated bug reports.
/tracker/{product-id}/{bug-id}
GET Gets the bug report.
POST Not supported.
PUT Update the bug report.
PATCH Not supported.
DELETE Delete the bug report.
/tracker/*/*
OPTIONS Discover the allowed operations over a resource
HEAD Only retrieve meta information about a resource

In the examples in this section, we will only focus on the container representation, creation and deletion of resources because that is where the Basic Containers, Direct Containers, and Indirect Containers differ. Other operations such as updating a resource would be similar to what was illustrated in the previous example.

Creation (POST a resource to an LDP-DC)

Continuing from the previous example, we can report a Bug against the "LDP Demo" product by creating a Bug report (an LDPR representing the bug) under the "LDP Demo" product description LDPC by posting a RDF representation of the Bug report to the LDPC associated with the product description.

The bug report document includes statements about the resource to be created. According the LDP specification, a client can use null relative URI (<>) in the request entity body to refer to resource to be created.

 
      

If the creation is successful, the server responds with location of the newly created resource.

HTTP/1.1 201 Created
Location: http://example.org/tracker/ldp-demo/bug67
Content-Length: 0           
      

If the creation fails, the server will respond with an appropriate status code depending on the error. If successful, the LDP Demo product description LDPC will have the following representation after the creation of new resource.


      

As you can see two new triples are added to the container. That is (</tracker/ldp-demo/>, <ldp:contains>, </tracker/ldp-demo/bug67>) and (</tracker/ldp-demo/#it>, <bt:hasbug>, </tracker/ldp-demo/bug67>). The former is added in any type of container and the latter is defined by the direct container properties.

The created Bug resource will have the following representation. Note that server has added a server managed property, creation date (dcterms:created), and a default value for the state (bt:isInState) to the Bug in addition to what was POSTed.

 

    

Deletion (DELETE on an LDPR associated with an LDP-DC)

This example illustrates the behaviour of a Direct Container when a resource is deleted.
 DELETE /tracker/ldp-demo/bug3 HTTP/1.1 
 Host: example.org
 If-Match: W/"123454322"
        

If the delete is successful, the server will respond with a success status code.

 HTTP/1.1 204 No Content
        

After the deletion, the representation of the container will look like the following


       
       

As seen from the LDP Direct Container representation above, both the containment triple (</tracker/ldp-demo/>, ldp:contains, </tracker/ldp-demo/bug3>) and the membership triple (</tracker/ldp-demo/#it>, bt:hasBug, </tracker/ldp-demo/bug3>) were removed from the container representation.

Extended Bug Tracker Example (LDP Indirect containers)

In this next example, we will use the same scenario as in the previous example, but change the container type to a LDP Indirect Container to show the differences between LDP Direct Containers and Indirect Containers and when to use LDP Indirect Containers. Though LDP Direct Containers provide the flexibility to define the constant membership URI (the subject of the membership triple when using ldp:hasMemberRelation or the object of the membership triple when using ldp:isMemberOfRelation) and the membership predicate, when creating members the member derived URI is always the newly created document URL. LDP Indirect containers provide more flexibility by allowing the member derived URI to be any resource; it could be either a non-information resource or a document other than the newly created resource. This done by defining the predicate to look for in the representation of the resource to be created by setting the ldp:insertedContentRelation predicate of the LDP Indirect Container. How this done will be explained in the following examples.

Creation (POST a resource to an LDP-IC)

Continuing from the previous example, we can create a new Bug Report against the 'LDP demo' product by creating a Bug Report LDPR under the 'LDP Demo' product description LDPC.

The client POSTs a representation of a Bug Report to the Bug Tracker LDPC.

 
      

One thing to note is that the representation of the resource to be created contains a triple (< >, foaf:primaryTopic , <#it>). If the create request is successful, the server responds with location of the newly created resource.

HTTP/1.1 201 Created
Location: http://example.org/tracker/ldp-demo/bug67
Content-Length: 0           
      

If the creation fails, the server will respond with an appropriate status code depending on the error. After the resource is creation, the Product A LDPC will have the following representation.


      

As you can see, two new triples are added to the container. That is (</tracker/ldp-demo/>, <ldp:contains>, </tracker/ldp-demo/bug67>) and (</tracker/ldp-demo/#it>, <bt:hasbug>, </tracker/ldp-demo/bug67#it>).

Security

It is not the focus of the Linked Data Platform WG to provide security mechanisms for read/write Linked Data applications; since LDP builds on HTTP, it can re-use any mechanism defined for HTTP. Though most of the security mechanisms that are applicable to general web applications are equally applicable to Linked Data applications, there is still some space to build security mechanisms specific to Linked Data applications by leveraging the Linked Data technologies and providing concrete security requirements for Linked Data applications. In this context, LDP WG has started to create a WG note on Access Control which aims to produce use cases for security scenarios of LDP applications that can be used as the input to a later initiative that will be focused on developing standard security mechanisms for LDP applications.

LDP Implementations

A list of implementations that plan to be LDP compliant is available in the LDP Implementations wiki page. The Linked Data Platform 1.0 - Implementation Reports provide the coverage of the specification by each LDP implementation.

What To Read Next

The primer only provide an overview of the Linked Data Platform specifications. LDP WG has produced following documents that contribute to the Linked Data Platform specification.

Acknowledgements

Many thanks to John Arwe (IBM), Ashok Malhotra (Oracle), and Henry Story (Apache Software Foundation) for their thorough review on the LDP Primer document and proposed corrections. We also like to thank all members of the Linked Data Platform WG for the valuable feedback.

Change History

The change history is up to the editors to insert a brief summary of changes, ordered by most recent changes first and with heading from which public draft it has been changed from.