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/',
containers: [
path: '/resources'
// Specific container options (See below)
defaultContainerOptions: {
// See below


baseUrlStringrequiredBase URL of the LDP server
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
podProviderBooleanfalseSet to true if your server is a POD provider
preferredViewForResourceFunctionFunction called to generate a redirect to the preferred view (see below)
resourcesWithContainerPathBooleantrueIf true, the URI of all new resources will include the container path

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.
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 catch-all routes are automatically added to the ApiGateway service.

MethodLDP resourceLDP containerActivityStreams collection
GET *ldp.resource.getldp.container.getactivitypub.collection.get
POST * defined by ControlledCollectionMixin)
PUT *ldp.resource.put--
PATCH *ldp.resource.patchldp.container.patch-
DELETE *ldp.resource.deleteldp.container.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.


The following service actions are available:


Allow other services to get access to the baseUrl setting of the LDP server.

Return values

The baseUrl setting.