Mesh REST Client

The portal uses the Java Mesh REST Client internally to load data from Gentics Mesh. A custom handler can get an instance of such a client via the injected MeshRestClientProvider.

Getting a client

A custom handler can inject the MeshRestClientProvider and use it to get instances of the Mesh REST client as shown in the following example.

Example using a Mesh REST client
// ...

@Inject
MeshRestClientProvider meshClientProvider;

// ...

@Override
public void handle(RoutingContext rc) {
    MeshRestClient client = meshClientProvider.get(rc);

    client.getApiInfo().toSingle().subscribe(info -> {
        log.info("Connected to Mesh version {}", info.getMeshVersion());
    });
}

User clients

When the BootstrapInitializer inserts the UserClientHandler, that handler will provide a Mesh REST Client using the authentication information from the AUTH cookie when the request is authenticated, or an anonymous client if it is not.

The MeshRestClientProvider will return these user clients, when they are available. Which means that loaded pages or navigation, are subject to user permissions set in Mesh.

When no user client is available the client provider will just return the admin client, which by default can load any data from Mesh.

Note that the user client handler can be used even when the portal does not do any authentication. In that case all requests to Mesh will be made using an anonymous client.

Using the client

Documentation for the Java Mesh REST Client is available on the Mesh homepage, and a simple example is available on Github.