|
| 1 | +# Constrained containers |
| 2 | + |
| 3 | +In CSS, it is possible to have containers where all its resources conform to a given [SHACL](https://www.w3.org/TR/shacl/) shape. |
| 4 | +Providing shape validation ensures that applications can then rely on the fact that |
| 5 | +the structure of the graph in the resources are valid. |
| 6 | + |
| 7 | +## Constrained containers in practice |
| 8 | + |
| 9 | +### Making a container constrained by a shape |
| 10 | + |
| 11 | +A container can be made shape constrained by editing its description resource. |
| 12 | +A triple of the form `?container ldp:constrainedBy ?shape .` must be added, |
| 13 | +where `?container` is the URL of the container being made constrained and `?shape` is the URL of the SHACL shape. |
| 14 | + |
| 15 | +A precondition for making a container constrained is that the container must not contain any resource at initialisation of making it shape constrained. |
| 16 | +Furthermore, it is only possible to initialise one shape resource per container. |
| 17 | + |
| 18 | +### Discovery of a constrained container |
| 19 | + |
| 20 | +Exposing that a container is constrained by shape is done through advertising a Link Header |
| 21 | +with `"rel"` `http://www.w3.org/ns/ldp#constrainedBy` as is defined in [LDP](https://www.w3.org/TR/ldp/) 4.2.1.6. |
| 22 | + |
| 23 | +## Impact of constraining a container |
| 24 | + |
| 25 | +Obviously, only resources can be created that conform to the constraints on a constrained container. |
| 26 | +However, some additional restrictions are enforced by the server on that container: |
| 27 | + |
| 28 | +* It is not possible to add any non-RDF resources. |
| 29 | +* Creating containers within this constrained container is not allowed. |
| 30 | +* Requests that results into a resource where no targetClasses from the shape are present are prohibited and will thus produce an error. |
| 31 | + |
| 32 | +## Example of a workflow on how to constrain a container |
| 33 | + |
| 34 | +In this example, we want to constrain a container `http://localhost:3000/container/` with a SHACL shape. |
| 35 | + |
| 36 | +We have started the CSS with the default configuration and have already created a container at `http://localhost:3000/container/` |
| 37 | +and added a SHACL shape at `http://localhost:3000/shape`. |
| 38 | + |
| 39 | +We make the container constrained by adding the constraint to the description resource of the container. |
| 40 | + |
| 41 | +```shell |
| 42 | +curl -X PATCH 'http://localhost:3000/container/.meta' \ |
| 43 | +-H 'Content-Type: text/n3' \ |
| 44 | +--data-raw '@prefix solid: <http://www.w3.org/ns/solid/terms#>. |
| 45 | +<> a solid:InsertDeletePatch; |
| 46 | +solid:inserts { <http://localhost:3000/container/> <http://www.w3.org/ns/ldp#constrainedBy> <http://localhost:3000/shape>. }.' |
| 47 | +``` |
| 48 | + |
| 49 | +After this update, we can verify that the container is indeed constrained with a shape by |
| 50 | +performing a `HEAD` request to container. |
| 51 | + |
| 52 | +```curl |
| 53 | +curl --head http://localhost:3000/container/ |
| 54 | +``` |
| 55 | +which will produce a response with at least this header: |
| 56 | + |
| 57 | +```HTTP |
| 58 | +Link: <http://localhost:3000/shape>; rel="http://www.w3.org/ns/ldp#constrainedBy" |
| 59 | +``` |
| 60 | + |
| 61 | +The container is now indeed constrained by the shape. |
| 62 | +This means that all the resources that will be added in this container are conform to the shape. |
| 63 | + |
| 64 | +In this example, we used a SHACL shape that was stored on the server. |
| 65 | +However, we can use any SHACL shape that can be fetched on the web via HTTP. |
0 commit comments