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 (application/ld+json, text/turtle or application/n-triples)
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
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")
Return values

Full URI available

get

  • Get a resource by its URI -Accept triples, turtle or JSON-LD (see @semapps/mime-types package)
Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of the resource
acceptstringrequiredType to return (application/ld+json, text/turtle or application/n-triples)
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.

patch

  • Partial update of an existing resource. Allow to add and/or remove tripled.
  • Accept either a SPARQL Update (with INSERT DATA and/or DELETE DATA) or 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.
Example query
PREFIX as: <https://www.w3.org/ns/activitystreams#>
INSERT DATA {
<http://localhost:3000/actor/virtual-assembly> as:name "Virtual Assembly" .
<http://localhost:3000/actor/virtual-assembly> as:location [
a as:Place ;
pair:label "Paris"
] .
};
DELETE DATA {
<http://localhost:3000/actor/virtual-assembly> as:name "VirtualAssembly" .
};
Parameters
PropertyTypeDefaultDescription
resourceUriStringrequiredURI of resource to update
sparqlUpdateStringSPARQL query with INSERT DATA and/or DELETE DATA operations
triplesToAddArrayArray of triples conforming with the RDF.js data model
triplesToRemoveArrayArray of triples conforming with the RDF.js data model
webIdStringLogged user's webIdUser doing the action
Return values
PropertyTypeDescription
resourceUriStringURI of the updated resource
triplesToAddArrayArray of triples conforming with the RDF.js data model
triplesToRemoveArrayArray of triples conforming with the RDF.js data model
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

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