Invoking External Services/API


Is there a way for me to leverage on the CUBA platform to rapidly build-up UI components and wire-up the respective action buttons to invoke external API calls (eg: where there are existing REST APIs being exposed by other legacy applications in the enterprise)?

Also, can this be done without the need to configure any data store/persistence for my new application built on CUBA platform (since the persistence tier in this enterprise setup is effectively residing on the other legacy applications)

Hi, Stan

I haven’t yet used REST API with Cuba Platform but I’m intending to do it soon. For this reason I discovered this documentation that could help you :
Hi, Stan


Thanks Xavier!

I’ve had a quick browse through on the documentation - it looks to concentrate on being able to provide REST APIs to allow other applications to interact with our CUBA platform-based application. I’m actually looking for the reverse scenario - where my UI components built on CUBA platform interacts with other applications via APIs.

Hi Stan,

You can create a set of non-persistent entities corresponding to the data model of your external services - see “Not persistent” option in the “Entity type” field of the “New CUBA Entity” dialog. Then use loadDelegate for data loaders and commitDelegate for DataContext to load and save data using your services instead of CUBA middleware.

A simpler solution would be using KeyValueEntity, below is an example of loading data from a REST service and displaying it in a table:

<window xmlns=""
    <data readOnly="true">
        <keyValueCollection id="namesDc">
        <dataGrid id="namesDataGrid" dataContainer="namesDc" height="100%" width="100%">
public class DemoScreen extends Screen {

    private KeyValueCollectionContainer namesDc;
    private DataGrid namesDataGrid;

    public void onInit(InitEvent event) {
        String jsonString = getJsonString();
        JSONArray jsonArray = new JSONArray(jsonString);

        if (jsonArray.length() > 0) {
            JSONObject jsonObject = jsonArray.getJSONObject(0);
            // initialize container properties and grid columns
            for (String key : jsonObject.keySet()) {
                namesDataGrid.addColumn(key, namesDc.getEntityMetaClass().getPropertyPath(key));

        // go through your data set
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            // create KeyValueEntity instances
            KeyValueEntity entity = new KeyValueEntity();
            for (String key : jsonObject.keySet()) {
                // set values
                entity.setValue(key, jsonObject.getString(key));
            // add entities to the container

    private String getJsonString() {
        String json;
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet("");
        try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
            json = EntityUtils.toString(response.getEntity());
        } catch (IOException e) {
            throw new RuntimeException(e);
        return json;

Thank you so much for this solution. It would be really helpful if you can provide any sample project for this.

Thank You!