Friday, November 7, 2014

Creating Containers in LDP, it is just this easy

I've heard a number of times that it isn't very clear how one creates a Linked Data Platform (LDP) Container.

Let's start with an example of how to create a simple resource (say LDP RDF Source).  You need to know a URL that accepts POST of the media type you want.
Here's the POST request:

1:  POST /netWorth/nw1/liabilities/ HTTP/1.1  
2:  Host:  
3:  Accept: text/turtle  
4:  Content-Type: text/turtle  
5:  Content-Length: 63  
7:  @prefix dcterms: <>.
8:  @prefix o: <>.
10:  <> a <>;
11:       dcterms:title "Home loan";
12:       o:value 200000.00 .
13:    # plus any other properties that the domain says liabilities have  

(Example "borrowed" from LDP spec example)

s Very simple, just POST some Turtle to a URL.

Now let's look at what it would look like to create a Container:

1:  POST /netWorth/nw1/liabilities/ HTTP/1.1  
2:  Host:  
3:  Accept: text/turtle  
4:  Content-Type: text/turtle  
5:  Content-Length: 72  
6:  Link: <>; rel="type"  
8:  @prefix dcterms: <>.
9:  @prefix o: <>.  
11:  <> a <> ;
12:       dcterms:title "Home loans" ;
13:       o:limit 500000.00 .   
14:    # plus any other properties  

That's it, just POSTing some content just like before. I added a Link header (line #6) on the POST request to be explicitly clear that I want this newly created resource to behave as an ldp:BasicContainer. Note that I wanted to be expressive so I included the type triple on line 11, though the spec doesn't require this as the Link header as the spec-defined way to clearly assign the desired behavior.

There are various other ways that ldp:Containers can come into existence, most of those reasons are dependent on the server's application-specific rules.  For example, an application might allow the creation of a resource of say "Customer", the application logic may determine to create a number of supporting Containers for the new Customer resource, such as which assets and liabilities they have.


  1. I think that your example is still confusing, especially to people with an RDF background.

    For example, was it important to say in the request body that `<>` is a Container? What happens if I don't say it? What if I say it but don't use the Link header?

    A better example would *completely* omit this triple. Or you should make explicit in your explanation that the body doesn't participate in the transaction, or more precisely that the specification doesn't specify the behaviour.

  2. Alexandre,
    Thanks for feedback. Your example shows the ongoing issues the diverse background members of the working group have. I was leaning a bit more towards the folks who don't have an RDF background. I updated the example to be a bit more descriptive.

    Questions you are asking getting into various edge cases and details that complete implementations would need to worry about, which is needed, my example was about finding the simplest thing that client or servers would need to worry about. Adding the details that is is a Container in the entity body, help clarify the interaction. It is completely up to the server to restrict the POST content based on its own logic. If a server wanted to be really flexible, of course it wouldn't require it, and then there is the opposite extreme.