LDP

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

Features

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

Dependencies

Sub-services

  • LdpContainerService
  • LdpResourceService

Install

$ npm install @semapps/ldp --save

Usage

const { LdpService } = require('@semapps/ldp');
module.exports = {
mixins: [LdpService],
settings: {
baseUrl: 'http://localhost:3000/',
ontologies : [
{
prefix: 'rdf',
url: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
},
{
prefix: 'ldp',
url: 'http://www.w3.org/ns/ldp#',
},
...
],
containers: [
'/resources'
]
}
};

Optionally, you can configure the API routes with moleculer-web:

const { ApiGatewayService } = require('moleculer-web');
module.exports = {
mixins: [ApiGatewayService],
dependencies: ['ldp'],
async started() {
[
...(await this.broker.call('ldp.getApiRoutes')),
// Other routes here...
].forEach(route => this.addRoute(route));
}
}

Settings

PropertyTypeDefaultDescription
baseUrlStringrequiredBase URL of the LDP server
ontologies[Object]requiredList of ontology used (see example above)
containers[String]/resourcesList of containers to set up, with their relative URL
defaultAcceptStringtext/turtleDefault Accept parameter used by all services

Actions

The following service actions are available:

ldp.resource.get

  • Get a resource by its URI
  • Accept triples, turtle or JSON-LD (see @semapps/mime-types package)
info

Action accessible through the API

GET <serveur>/<container>/identifier
Parameters
PropertyTypeDefaultDescription
resourceUriStringrequireduri of getting subject
acceptstringrequiredType to return (application/ld+json, text/turtle or application/n-triples)
webIdstringLogged user's webIdUser doing the action
queryDepthInteger0Depth of resource resolution. Resolves only blank nodes, not objects with IDs.
jsonContextArray, Object or StringCompact the returned resource with this context. Only works with JSON-LD.
Return

Triples, Turtle or JSON-LD depending on Accept type.

ldp.resource.post

  • Create a resource
  • Content-type can be triples, turtle or JSON-LD (see @semapps/mime-types package)
info

Action accessible through the API

POST <serveur>/<container>
Parameters
PropertyTypeDefaultDescription
resourceString or ObjectrequiredResource to create
containerUristringrequiredContainer where the resource will be created
contentTypestringrequiredType of provided resource (application/ld+json, text/turtle or application/n-triples)
webIdstringLogged user's webIdUser doing the action
slugStringSpecific ID tu use for URI instead generated UUID
Return

String : URI of the created resource

ldp.resource.patch

  • Partial update of an existing resource. Only the provided predicates will be replaced.
  • Content-type can be triples, turtle or JSON-LD (see @semapps/mime-types package)
info

Action accessible through the API

PATCH <serveur>/<container>/identifier
Parameters
PropertyTypeDefaultDescription
resourceString or ObjectrequiredResource to update
contentTypestringrequiredType of provided resource (application/ld+json, text/turtle or application/n-triples)
webIdstringLogged user's webIdUser doing the action
Return

String : URI of the updated resource

ldp.resource.put

  • Full update of an existing resource
  • If some predicates existed but are not provided, they will be deleted.
  • Content-type can be triples, turtle or JSON-LD (see @semapps/mime-types package)
info

Action accessible through the API

PUT <serveur>/<container>/identifier
Parameters
PropertyTypeDefaultDescription
resourceString, ObjectrequiredResource to update
contentTypestringrequiredType of provided resource (application/ld+json, text/turtle or application/n-triples)
webIdstringLogged user's webIdUser doing the action
Return

String : URI of the updated resource

ldp.resource.delete

  • Delete the whole resource and detach it from its container
info

Action accessible through the API

DELETE <serveur>/<container>/id
Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of resource to delete
webIdstringLogged user's webIdUser doing the action
Return

None

ldp.container.attach

  • Attach a resource to a container
Parameters
PropertyTypeDefaultDescription
containerUriStringrequiredURI of container to which the resource will be attached
resourceUriStringrequiredURI of resource to attach
Return

None

ldp.container.detach

  • Detach a resource from a container
Parameters
PropertyTypeDefaultDescription
containerUriStringrequiredURI of container to which the resource will be detached
resourceUriStringrequiredURI of resource to attach
Return

None

ldp.container.exist

  • Check if container exists
Parameters
PropertyTypeDefaultDescription
containerUriStringrequiredURI of container to check
Return

true or false

ldp.container.create

  • Create a new LDP container
Parameters
PropertyTypeDefaultDescription
containerUriStringrequiredURI of the container to create
Return

None

ldp.container.get

  • Get all resources attached to a container
  • Use the LDP ontology of direct containers
info

Action accessible through the API

GET <serveur>/<container>
Parameters
PropertyTypeDefaultDescription
containerUriStringrequiredURI of container
acceptstringrequiredType to return (application/ld+json, text/turtle or application/n-triples)
queryObjectnullreturn only triples which predicate is key and value is value of object parameter
queryDepthInteger0Depth of resource resolution. Resolves only blank nodes, not objects with IDs.
jsonContextArray, Object or StringCompact the returned resource with this context. Only works with JSON-LD.
webIdstringLogged user's webIdwebId used to identify user doing action on tripleStore
Return

Triples, Turtle or JSON-LD depending on Accept type

ldp.getApiRoutes

Return

Object - Routes formatted for the Moleculer ApiGateway