Breadcrumb
- Sabre Red 360 Software Development Kit Help
- Web Red Apps
- Sabre Red 360 Services
- ExternalServiceConnector
ExternalServiceConnector
Sabre Red 360 Software Development Kit provides a capability to call an external service via HTTP protocol.
Usage with TypeScript
The ExternalServiceConnector allows to call external services via HTTP in Web Module.
Acquiring ExternalServiceConnector
In order to obtain ExternalServiceConnector and use it, you need to import it:
import {ExternalServiceConnector} from 'sabre-ngv-app/app/services/impl/ExternalServiceConnector';
Then obtain the service inside your source as below:
const externalServiceConnector: ExternalServiceConnector = getService(ExternalServiceConnector);
Available methods
callService |
---|
Type Parameters:
Returns: Call to the service is performed asynchronously and the result is returned as NgvPromise which returns a JSON string with the response. |
Example
Below you can find a sample call to a service using the POST method, sending 'Sample request body' and setting a 'Cookie' header with 'myCookie' value:
const externalServiceConnector = getService(ExternalServiceConnector);
externalServiceConnector.callService(
'https://example.com/users',
'POST',
'Sample request body',
{ Cookie: 'myCookie' }
).done(this.updateModel);
When the call is completed and response is received the function registered with .done is executed. It takes one argument which is a JSON string containing a response from the service.
private updateModel(data: Object) {
const response = JSON.parse(data.toString()).responseBody;
this.getModel().set('serviceResponse', { response: response.payload });
this.render();
}