Red Hat Training

A Red Hat training course is available for Red Hat JBoss Data Virtualization

4.3. Using Repositories with REST in EAP

4.3.1. RESTful API

The RESTful API is a simple JAX-RS web application that is packaged as a WAR file, and the kit automatically deploys this WAR file. HTTP clients use the hierarchical database's RESTful API. Hence it is easy to write a simple client application to read and write repository content using the RESTful API. However, since your web browser is a simple HTTP client, you can use it to directly interact with the RESTful API. The RESTful API automatically installs when you install the hierarchical database into a JBoss EAP installation.

4.3.2. Using RESTful API to Check the Availability of the Repositories

Procedure 4.12. Task

  1. To use the RESTful API to check the health and availability of the repositories, point your browser to http://localhost:8080/modeshape-rest/. This results in a JSON response that is similar to the following:
    
    {
        "sample": {
            "repository": {
                "name": "sample",
                "resources": {
                    "workspaces": "/modeshape-rest/sample"
                },
                "metadata": {
                    "option.retention.supported": "false",
                    ...
                }
            }
        }
    }
    
    The response document lists the named repositories that are available. In this case, there is only one "sample" repository, and its nested document provides the name, resources and metadata for the repository. The "resources" nested document contains the usable (relative) link.
  2. To use the link to get more information about the repository, issue a GET to the resource at http://localhost:8080/modeshape-rest/sample, which you can do by pointing your browser to this URL. When you do this, the RESTful service returns a JSON response document describing the "sample" repository as shown below:
    
    {
        "default": {
            "workspace": {
                "name": "default",
                "resources": {
                    "query": "/modeshape-rest/sample/default/query",
                    "items": "/modeshape-rest/sample/default/items"
                }
            }
        }
    }
    
    This document describes the repository and lists the named workspaces. In this case, there is a single "default" workspace, and the following resources available for use:
    • http://localhost:8080/modeshape-rest/sample/default/items exposes the repository's nodes via RESTful methods.
    • http://localhost:8080/modeshape-rest/sample/default/query allows RESTful clients to POST queries and receive responses containing the results.
  3. Continue to navigate the content of the "default" workspace in the "sample" repository. You can not issue a POST with your web browser without some HTML/JavaScript content on the page. For example, if you point your browser to http://localhost:8080/modeshape-rest/sample/default/items, you will get a response that describes the root node of that workspace:
    
    {
        "properties": {
            "jcr:primaryType": "mode:root",
            "jcr:uuid": "81513257505d64/"
        },
        "children": ["jcr:system"]
    }
    
    Here, the root node has two properties, jcr:primaryType and jcr:uuid (since the node is also mix:referenceable), and one child node jcr:system.
  4. You can append the child name to your URL (for example, http://localhost:8080/modeshape-rest/sample/default/items/jcr:system) to get the information about the "/jcr:system" node:
    {
        "properties": {
            "jcr:primaryType": "mode:system"
        },
        "children": ["jcr:nodeTypes", "jcr:versionStorage", "mode:namespaces", "mode:locks"]
    }
    Here, the "/jcr:system" node has only one property but has four children.
  5. You can look at the mode:namespaces child node by pointing your browser to http://localhost:8080/modeshape-rest/sample/default/items/jcr:system/mode:namespaces to get its JSON representation:
    
    {
        "properties": {
            "jcr:primaryType": "mode:namespaces"
        },
        "children": ["jcr", "nt", "mix", "sv", "mode", "xml", "xmlns", "xs", "xsi"]
    }
    
    
    Here, you can see only one property, while there are 9 children, one for each registered namespace, where the node name is the namespace prefix.
  6. You can get the JSON representation of the "jcr" namespace by pointing your browser to http://localhost:8080/modeshape-rest/sample/default/items/jcr:system/mode:namespaces/jcr:
    
    {
        "properties": {
            "jcr:primaryType": "mode:namespace",
            "mode:generated": "false",
            "mode:uri": "http:\/\/www.jcp.org\/jcr\/1.0"
        }
    }
    
    Here, the "/jcr:system/mode:namespaces/jcr" node has three properties and no children.