Skip to main content


This package allows you to setup LDP containers in which LDP resources can be manipulated.


  • Handles triples, turtle and JSON-LD format
  • Automatic creation of containers on server start
  • Full container management: create, attach resources, detach, clear, delete...





$ yarn add @semapps/ldp


const { LdpService } = require('@semapps/ldp');

module.exports = {
mixins: [LdpService],
settings: {
baseUrl: 'http://localhost:3000/',
ontologies : [
prefix: 'rdf',
url: ''
prefix: 'ldp',
url: '',
containers: [
path: '/resources',
// Specific container options (See below)
defaultContainerOptions: {
// See below


baseUrlStringrequiredBase URL of the LDP server
ontologies[Array]requiredList of ontology used (see example above)
containers[Object]requiredList of containers to set up, with their options (see below)
defaultContainerOptions[Object]Default options for all containers (see below)
mirrorGraphNameString""Name of the RDF graph where to store mirrored data
podProvider[Boolean]falseSet to true if your server is a POD provider
preferredViewForResourceFunctionFunction called to generate a redirect to the preferred view (see below)

Container options

The following options can be set for each container, or they can be set in the defaultContainerOptions settings.

acceptString"text/turtle"Type to return (application/ld+json, text/turtle or application/n-triples)
acceptedTypesArrayRDF classes accepted in this container. This is not enforced but used by some services to identify containers.
excludeFromMirrorBooleanfalseIf true, other servers will not be able to mirror this container.
jsonContextAnyJSON context to use to format results
dereferenceArrayBlank nodes to dereference, prefixed with their ontology. You can define sub-predicates separated by /
queryDepthInteger0Depth of blank nodes to dereference (Deprecated. Will be removed in a future minor release.)
permissionsObject or FunctionIf the WebACL service is activated, permissions of the container itself
newResourcesPermissionsObject or FunctionIf the WebACL service is activated, permissions for new resources. See the docs here
readOnlyBooleanfalseDo not set POST, PATCH, PUT and DELETE routes for the container and its resources
preferredViewStringA part of the final URL for redirecting to the preferred view of the resource (see below).
controlledActionsObjectUse custom actions instead of the LDP ones (post, list, get, create, put, patch, delete). Used by the ControlledContainerMixin

API routes

These routes are automatically added to the ApiGateway service.

RouteAction called
GET /<container>ldp.container.get
POST /<container>
PATCH /<container>ldp.container.patch
GET /<container>/<resource>ldp.resource.get
PATCH /<container>/<resource>ldp.resource.patch
PUT /<container>/<resource>ldp.resource.put
DELETE /<container>/<resource>ldp.resource.delete

Note: If the readOnly container option is set (see above), only GET routes are added.

Redirecting to a frontend app

When a browser visits the URL of an LDP resource, for example, with an Accept header containing text/html, you have the ability to redirect the browser to your preferred view on the frontend of your application.

In order to configure this feature, you should add the following configurations :

  1. For each container that you want to setup a redirect, add the preferredView option:
const containers = [
path: '/users',
preferredView: '/Person/',
// Other container options...
{ ... }
  1. Set the preferredViewForResource setting with a function like this one which will receive the preferredView option set above:
function preferredViewForResource(resourceUri, containerPreferredView) {
if (!containerPreferredView) return resourceUri;
return '' + containerPreferredView + encodeURIComponent(resourceUri) + '/show'

The function should return the redirect link. It can be async. Return resourceUri if you want to cancel the redirect.