Managing schemas and APIs using the Service Registry Java client

Guide
  • Red Hat OpenShift Service Registry 1
  • Updated 02 December 2021
  • Published 24 September 2021

Managing schemas and APIs using the Service Registry Java client

Guide
Red Hat OpenShift Service Registry 1
  • Updated 02 December 2021
  • Published 24 September 2021

Manage schema and API artifacts stored in the Red Hat OpenShift Service Registry cloud service using the Service Registry Java client classes in your client application.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code and documentation. We are beginning with these four terms: master, slave, blacklist, and whitelist. Due to the enormity of this endeavor, these changes will be gradually implemented over upcoming releases. For more details on making our language more inclusive, see our CTO Chris Wright’s message.

Service Registry Java client

You can manage artifacts stored in Service Registry using a Java client application. You can create, read, update, or delete artifacts stored in the registry using the Service Registry Java client classes. You can also perform admin functions using the client, such as managing global rules or importing and exporting registry data.

You can access the Service Registry Java client by adding the correct dependency to your project. For more details, see Writing Service Registry Java client applications.

The Service Registry client is implemented using the HTTP client provided by the JDK. This gives you the ability to customize its use, for example, by adding custom headers or enabling options for Transport Layer Security (TLS) authentication. For more details, see Service Registry Java client configuration.

Writing Service Registry Java client applications

This section explains how to manage artifacts stored in Service Registry using a Java client application.

Prerequisites
  • You have a service account with the correct access permissions for Service Registry instances

Procedure
  1. Add the following dependency to your Maven project:

    <dependency>
        <groupId>io.apicurio</groupId>
        <artifactId>apicurio-registry-client</artifactId>
        <version>${apicurio-registry.version}</version>
    </dependency>
  2. Create a registry client as follows:

    public class ClientExample {
    
        private static final RegistryRestClient client;
    
         public static void main(String[] args) throws Exception {
            // Create a registry client
            String registryUrl = "https://my-registry.my-domain.com/apis/registry/v2";
            RegistryClient client = RegistryClientFactory.create(registryUrl);
        }
    }
    • If you specify an example registry URL of https://my-registry.my-domain.com, the client will automatically append /apis/registry/v2.

    • For more options when creating a Service Registry client, see the Java client configuration in the next section.

When the client is created, you can use all the operations available in the Service Registry REST API in the client. For more details, see the Apicurio Registry REST API documentation.

Additional resources

Service Registry Java client configuration

The Service Registry Java client includes the following configuration options, based on the client factory:

Table 1. Service Registry Java client configuration options
Option Description Arguments

Plain client

Basic REST client used to interact with a running registry.

baseUrl

Client with custom configuration

Registry client using the configuration provided by the user.

baseUrl, Map<String Object> configs

Client with custom configuration and authentication

Registry client that accepts a map containing custom configuration. This is useful, for example, to add custom headers to the calls. This also requires providing an auth instance used to authenticate requests.

The OpenShift Application Services authentication server is https://identity.api.openshift.com/auth/realms/rhoas/protocol/openid-connect/token

baseUrl, Map<String Object> configs, Auth auth

Custom header configuration

To configure custom headers, you must add the apicurio.registry.request.headers prefix to the configs map key. For example, a key of apicurio.registry.request.headers.Authorization with a value of Basic: xxxxx results in a header of Authorization with value of Basic: xxxxx.

TLS configuration options

You can configure Transport Layer Security (TLS) authentication for the Service Registry Java client using the following properties:

  • apicurio.registry.request.ssl.truststore.location

  • apicurio.registry.request.ssl.truststore.password

  • apicurio.registry.request.ssl.truststore.type

  • apicurio.registry.request.ssl.keystore.location

  • apicurio.registry.request.ssl.keystore.password

  • apicurio.registry.request.ssl.keystore.type

  • apicurio.registry.request.ssl.key.password

Additional resources