Package com.inrupt.client.solid


package com.inrupt.client.solid

Support for Solid specific concepts for the Inrupt Java Client Libraries.

Solid Client

This Solid domain-specific module contains two dedicated Solid clients you can make use of: SolidClient which works asynchronously and SolidSyncClient which works synchronously.

One can instantiate a Solid client in different ways, depending on the use case:

A simple direct way is with the following line:


    SolidClient client = SolidClient.getClient();
    
 

This will make use of the client that is currently loaded on the classpath. (If you have the core module (inrupt-client-core) loaded, this will make use of the DefaultClient).

The above line is equivalent to:


    Client classPathClient = ClientProvider.getClient();
    SolidClient client = SolidClient.getClientBuilder().client(classPathClient).build();
    
 

The Solid client can be used to perform CRUD operations on Solid resources.

In this example, the client reads a Solid resource as a Playlist object.


    var playlist = client.read(uri, Playlist.class);
    playlist.thenAccept(p -> {
        displayTitle(p.getTitle());
        displaySongs(p.getSongs());
    }).toCompletableFuture().join(); 
 

One may also create new resources.


    var playlist = new Playlist(uri);
    playlist.setTitle("Jazz Collection");
    playlist.addSong(song1);
    playlist.addSong(song2);

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

Or update existing resources.


    var playlist = client.read(uri, Playlist.class);

    playlist.thenCompose(p -> {
        p.setTitle("Bossa Nova");
        p.removeSong(song1);
        p.addSong(song3);
        return client.update(p);
    }).toCompletableFuture().join(); 
 

Or delete resources.


    client.delete(uri).toCompletableFuture().join(); 
 

Solid RDFSource and Solid Container

This module also contains a BodyHandler which consumes the response body and converts it into a SolidRDFSource or a SolidContainer Java object.

The following example reads a Solid Container and presents it as a SolidContainer Java object:


        Request request = Request.newBuilder()
            .uri(URI.create("https://solid.example/storage/"))
            .header("Accept", "text/turtle")
            .GET()
            .build();

        Response<SolidContainer> response = client.send(
            request,
            SolidResourceHandlers.ofSolidContainer()
        ).toCompletableFuture().join();
        System.out.println("HTTP status: " + response.statusCode());
        System.out.println("Resource URI: " + response.body().getId());