CRUD#

Both SolidSyncClient and SolidClient provide methods for reading and writing resources to your Solid Pod; that is, performing create/read/update/delete (CRUD) operations. The resources can be RDF resources as well as non-RDF resources (such as .jpg, .pdf, .txt, .json files).

The SolidSyncClient and SolidClient provide methods to perform CRUD operations on Pod resources (both RDF resources and non-RDF resources).

SolidClient#

SolidClient is an asynchronous client for interacting with Solid resources.

SolidClient client = SolidClient.getClient();

For an authenticated client, pass the authenticated Session object to the client:

client.session(mySession);

See also:

.create()#

SolidClient.create() creates a new resource (SolidRDFSource, SolidContainer, and SolidNonRDFSource) at the specified location in your Pod.

For example, assume an Expense class that extends SolidRDFSource. To save an Expense object to a Pod, pass the object to the method:

client.create(newExpense).toCompletableFuture().join();

Note

  • If any container in the location path does not exist, the method creates the missing containers as well as the resource.

  • If the resource already exists at the location, the operation errors with PreconditionFailedException. Use .update() instead.

.read()#

SolidClient.read() reads a resource (SolidRDFSource, SolidContainer, and SolidNonRDFSource) from your Pod and map to a specified class.

For example, assume an Expense class that extends SolidRDFSource. To read the Expense resource from a Pod, pass the resource’s identifier (i.e., its URI) and the class:

Expense myExpense = client.read(
   URI.create("https://..."),
   Expense.class).toCompletableFuture().join();

.update()#

SolidClient.update() updates a resource (SolidRDFSource, SolidContainer, and SolidNonRDFSource) in your Pod.

  • If the resource does not exist at the location, creates a new resource.

  • If the resource already exists at the location, overwrites the resource.

For example, assume an Expense class that extends SolidRDFSource. To update (or create) an Expense resource in a Pod, pass the object to the method:

// ... Modify the fetched expense
// myExpense.setXXX(...);
// myExpense.setYYY(...);

// Update the RDF resource at the location
// specified in the myExpense's identifier field.

Expense response = client.update(myExpense).toCompletableFuture().join();

.delete()#

SolidClient.delete() deletes a resource (SolidRDFSource, SolidContainer, and SolidNonRDFSource) from your Pod.

  • You can specify the URL of the resource to delete:

    client.delete(URI.create("https://...")).toCompletableFuture().join();
    

or

  • You can pass the object to delete:

    For example, assume an Expense class that extends SolidRDFSource.

    client.delete(new Expense(URI.create("https://..."))).toCompletableFuture().join();
    

Tip

To delete a SolidContainer, the SolidContainer must be empty.

SolidSyncClient#

SolidSyncClient is a synchronous client for interacting with Solid resources.

SolidSyncClient client = SolidSyncClient.getClient();

For an authenticated client, pass the authenticated Session object to the client:

client.session(mySession);

See also:

.create()#

SolidSyncClient.create() creates a new resource (SolidRDFSource, SolidContainer, and SolidNonRDFSource) at the specified location in your Pod.

For example, assume an Expense class that extends SolidRDFSource. To save an Expense object to a Pod, pass the object to the method:

client.create(newExpense);

Note

  • If any container in the location path does not exist, the method creates the missing containers as well as the resource.

  • If the resource already exists at the location, the operation errors with PreconditionFailedException. Use .update() instead.

.read()#

SolidSyncClient.read() reads a resource (SolidRDFSource, SolidContainer, and SolidNonRDFSource) from your Pod and map to a specified class.

or example, assume an Expense class that extends SolidRDFSource. To read the Expense resource from a Pod, pass the resource’s identifier (i.e., its URI) and the class:

Expense myExpense = client.read(
   URI.create("https://..."),
   Expense.class);

.update()#

SolidSyncClient.update() updates a resource in your Pod.

  • If the resource does not exist at the location, creates a new resource.

  • If the resource already exists at the location, overwrites the resource.

For example, assume an Expense class that extends SolidRDFSource. To update (or create) an Expense resource in a Pod, pass the object to the method:

// ... Modify the fetched expense
// myExpense.setXXX(...);
// myExpense.setYYY(...);

// Update the RDF resource at the location
// specified in the myExpense's identifier field.

Expense response = client.update(myExpense);

.delete()#

SolidSyncClient.delete() deletes a resource (SolidRDFSource, SolidContainer, and SolidNonRDFSource) from your Pod.

  • You can specify the URL of the resource to delete:

    client.delete(URI.create("https://..."));
    

or

  • You can specify the object to delete:

    For example, assume an Expense class that extends SolidRDFSource.

    client.delete(new Expense(URI.create("https://...")));
    

Tip

To delete a SolidContainer, the SolidContainer must be empty.

Headers#

You can use the resource class’ getHeaders() method to get the headers:

See also Appendix: Headers.

Alternatively, you can also use the resource class’ getMetadata() methods:

The getMetadata() methods return Solid-specific data (parsed into Java types) from a resource’s response headers. To access the complete set of response headers, use the getHeaders() methods.