Skip to main content

LdpResourceService

This service is automatically created by the LdpService

Actions

The following service actions are available:

create

  • This action is called internally by ldp.container.post
  • If called directly, the full URI must be provided in the @id of the resource object
Parameters
PropertyTypeDefaultDescription
resourceObjectrequiredResource to create (with an ID)
contentTypeStringrequiredType of provided resource
webIdStringLogged user's webIdUser doing the action
Return values
PropertyTypeDescription
resourceUriStringURI of the created resource
newDataObjectNew value of the resource
webIdStringUser who did the action

delete

Delete the whole resource and detach it from its container

Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of resource to delete
webIdstringLogged user's webIdUser doing the action
Return values
PropertyTypeDescription
resourceUriStringURI of the deleted resource
oldDataObjectOld value of the resource
webIdStringUser who did the action

exist

  • Check if a resource exist
Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of the resource to check
acceptTombstonesBooleantrueIf false, calling this action on a Tombstone will return false
webIdStringLogged user's webIdUser doing the action
Return values

Boolean

generateId

Finds an unique ID for a resource

Parameters
PropertyTypeDefaultDescription
containerUriStringrequiredURI of the container where to create the resource
slugStringPreferred slug (will be "slugified")
isContainerBooleanfalseSet to true if you want to generate a container's ID
Return values

Full available URI

get

  • Get a resource by its URI -A ccept triples, turtle or JSON-LD (see @semapps/mime-types package)
Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of the resource
acceptstringrequiredType to return
webIdstringLogged user's webIdUser doing the action

You can also pass any parameter defined in the container options.

Return

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

getContainers

Get the list of containers which includes the resource

Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of the resource
datasetStringrequired in Pod provider configThe dataset in which to look for the containers
Return

An array of containers URIS

getTypes

Get the type(s) of the given resource

Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of the resource
Return

An array of types

patch

  • Partial update of an existing resource. Allow to add and/or remove tripled.
  • Takes an array of triples conforming with the RDF.js data model
  • You can add blank nodes but not remove them (this is a limitation of the SPARQL specifications for DELETE DATA)
  • If you try to modify triples not linked to the PATCH resource, it will throw an error.
Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of resource to update
triplesToAddArrayTriples to add, in RDF/JS format. See below for details.
triplesToRemoveArrayTriples to remove, in RDF/JS format. See below for details.
webIdStringLogged user's webIdUser doing the action

Example usage:

const { triple, namedNode } = require('@rdfjs/data-model');

await this.broker.call('ldp.resource.patch', {
containerUri: 'http://localhost:3002/my-resource',
triplesToAdd: [
triple(
namedNode('http://localhost:3002/my-resource'),
namedNode('http://purl.org/dc/terms/creator'),
namedNode('http://localhost:3002/alice')
)
]
});
Return values
PropertyTypeDescription
resourceUriStringURI of the updated resource
triplesAddedArrayArray of triples which were addeed
triplesRemovedArrayArray of triples which were removed
webIdStringUser who did the action

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)
Parameters
PropertyTypeDefaultDescription
resourceObjectrequiredResource to update
contentTypestringrequiredType of resource (application/ld+json, text/turtle or application/n-triples)
webIdstringLogged user's webIdUser doing the action
Return values
PropertyTypeDescription
resourceUriStringURI of the updated resource
newDataObjectNew value of the resource
oldDataObjectOld value of the resource
webIdStringUser who did the action

upload

Upload a given file and return its JSON-LD representation

Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of the file resource. Will be used when choosing the path of the file.
fileFilerequiredFile to upload
Return values

The JSON-LD representation of the uploaded file (using the semapps:File predicate).

Events

The following events are emitted.

ldp.resource.created

Sent after a resource is created.

Payload
PropertyTypeDescription
resourceUriStringURI of the created resource
newDataObjectNew value of the resource
webIdStringUser who did the action

ldp.resource.deleted

Sent after a resource is deleted.

Payload
PropertyTypeDescription
resourceUriStringURI of the deleted resource
oldDataObjectOld value of the resource
webIdStringUser who did the action

ldp.resource.patched

Sent after a resource is patched

Payload
PropertyTypeDescription
resourceUriStringURI of the updated resource
triplesAddedArrayArray of triples conforming with the RDF.js data model
triplesRemovedArrayArray of triples conforming with the RDF.js data model
webIdStringUser who did the action

ldp.resource.updated

Sent after a resource is updated (through PUT)

Payload
PropertyTypeDescription
resourceUriStringURI of the updated resource
newDataObjectNew value of the resource
oldDataObjectOld value of the resource
webIdStringUser who did the action