Skip to main content

CF Api

Web Modules can send or receive data from Java services defined inside of the Red App by using Command Flow framework.

Use cf() to send or receive data using Command Flow framework.

Sending Requests using Command Flow

Below you can see how to send a simple request  

cf('NGV://REDAPP/SERVICE/<Service Id>;').send()

and how to add a request with payload

cf('NGV://REDAPP/SERVICE/<Service Id>').addRequestDataObject(new SmapleRq(payload)).setLocalPreference('silent', true).send

Receiving Data using Command Flow

to receive data

cf('NGV://REDAPP/SERVICE/<Service Id>').addRequestDataObject(new SampleRq(payload)).setLocalPreference('silent', true).retrieveData(SampleData)

Refer to Command Flow typescript documentation for more options.

to register Model class to a response structure

getService(DtoService).registerDataModel('[.Structure][.ExtensionPoint_Summary][.SampleRs]', SampleData);

[.Structure][.ExtensionPoint_Summary][.SampleRs] is the response format that is received from the Command Flow.

Model can be created by extending app.common.data.dto.Data or app.common.data.dto.ResponseData

ResponseData has additional method isScreenOnly.

Example class:

import {Initial} from 'sabre-ngv-core/decorators/classes/Initial';
import AbstractModelOptions = app.AbstractModelOptions;
import EnhancedResponseData = app.common.data.dto.ResponseData;
import DataOptions = app.common.data.dto.DataOptions;

@Initial<DataOptions>({
    dataRoot: '[d.Structure][d.ExtensionPoint_Summary][sample.SampleRs]'
})

export class SampleData extends ResponseData {
    /*
    * Method to extract data from response by passing JSON node
    * In this case fromRoot() returns extracted response from the dataRoot defined above.
    * Below code looks for array of SampleData under the dataRoot.
    */
    getData(): Array<string> {
        return this.fromRoot().get<Array<JSON>>('[SampleData]').value();
   }
}

to register View class to Model class

getService(DtoService).registerDataView (SampleData, SampleView);

import {Template} from 'sabre-ngv-core/decorators/classes/view/Template';
import AbstractView = app.AbstractView;
import AbstractViewOptions = app.AbstractViewOptions;
import AbstractModel = app.AbstractModel;

@Initial<AbstractViewOptions>({
    title: 'Sample View',
 })

/*
*Sample is the html template file
*/
@Template('sample-webmodule:Sample')
export class SampleView extends AbstractView<AbstractModel> {



}

Refer to example com.sabre.redapp.example3.web.tilewidgets for more details.