=======================
Java Client Usage
=======================

The Resource Registry provides Java client libraries for easy integration.

**Maven Dependency:**

.. code-block:: xml

    <dependency>
        <groupId>org.gcube.information-system</groupId>
        <artifactId>resource-registry-client</artifactId>
    </dependency>

**Basic Usage Example:**

.. code-block:: java

    import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
    import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;

    // Get client instance
    ResourceRegistryClient client = ResourceRegistryClientFactory.create();

    // Read a resource
    EService service = client.read(EService.class, uuid);

    // Create a resource
    EService newService = new EService();
    // ... set facets ...
    client.create(newService);

**Methods Result:**

The service exposes `its methods <../api-docs/index.html>`_ using a standard naming approach.
Moreover, they accept (in the case of HTTP POST/PUT methods) JSON objects. 

.. IMPORTANT::
   The result of all methods is always a JSON object as per below:

.. code:: javascript

  {
      ....
  }

*Inputs are automatically validated before the request is served.*

================
Examples
================

**Creating a Service Resource:**

.. code-block:: rest

    PUT /instances/EService/550e8400-e29b-41d4-a716-446655440000
    Content-Type: application/json
    Authorization: Bearer your-oidc-token

    {
        "type": "EService",
        "consistsOf": [
            {
                "type": "IsIdentifiedBy",
                "target": {
                    "type": "SoftwareFacet",
                    "group": "org.example",
                    "name": "my-service",
                    "version": "1.0.0"
                }
            },
            ...
        ]
    }

**Querying Resources:**

.. code-block:: rest

    GET /access/instances/EService?polymorphic=true&includeMeta=true

**Adding Resource to Context:**

.. code-block:: rest

    PUT /sharing/contexts/{context-uuid}/EService/{resource-uuid}?operation=ADD
