Skip Navigation

RestApiService

RestApi Client for 2SG

Acquiring RestApi

In order to obtain RestApi and use it you need to import it, e.g.

import {RestApiService} from "sabre-ngv-communication/services/RestApiService";

Afterwards, inside your source, get the service in the way outlined below:

const restApi = getService(RestApiService);

Available methods

send
send(request: RestRq): Promise<RestResponse>;

Type Parameteres:

  • request - RestRq object containing request parameters

RestRq {
    httpMethod: HttpMethod;
    url: string;
    authTokenType?: AuthTokenType;
    payload?: string;
    lockId?: number;
    headers?: string;
    timeout?: number;
}
  • httpMethod - 'GET' 'POST' 'PUT' 'DELETE' 'HEAD' 'CONNECT' 'OPTIONS' 'TRACE' 'PATCH';

  • url - url of request

  • [authTokenType] - 'SESSION' or 'SESSIONLESS'

  • [payload] - JSON-formatted string of request body (for DELETE requests payload is ignored)

  • [lockId] - id of the lock you want to inject into the request

  • [headers] - JSON-formatted string request headers.

  • [timeout] - timeout period

Returns:
Promise<RestResponse>

sendExternal

sendExternal(request: RestRq, options?: JsonObject, contentType: string = 'application/json') : Promise<RestResponse>

Type Parameters:

  • request - RestRq object containing request parameters, see above

  • [options] - optional object, no additional options are supported at the moment.

  • [contentType] - optional string, default content type is application/json. It can be changed using this parameter. If it’s set then it’s going to be used over 'Content-Type' header in request.

Returns:
Promise<RestResponse>

The response from the service is structured as follows below:

export interface RestResponse {
    status: string,
    body: JsonObject | string,
    error?: JsonObject,
    headers?: RestResponseHeaders
}
export interface RestResponseHeaders {
    [key: string]: string
}
  • status - status code

  • body - body of the response, depends on content-type returned as JsonObject or string

  • [error] - JsonObject with response errors

  • [headers] - List of [key, value] pairs of response headers

Important
In Sabre Red Web, because of the way the browser handles rest calls, if there is an error (e.g. net::ERR_CONNECTION_REFUSED) the API may not be able to catch it and return it in RestResponse, the error should still show up in the console.

Working with headers

Headers should be provided in json-formatted string. Sabre REST services are returning 400 Bad Request response if unknown header is used.

Authorization in redapp.xml

To be able to connect to a Sabre 2SG REST endpoint, e.g.:

/v1/lists/utilities/aircraft/equipment

Or:

/v1/historical/flights/{destination}/seasonality

You need to add authorization to redapp.xml:

<CFBundle>
    <RedApp id="rest-comm-sabre-sample">
        <Authorization name="com.sabre.edge.cf.rest2sg.Rest2Sg">
            <Action name="/v1/lists/utilities/aircraft/equipment" threshold="1" />
            <Action name="/v1/historical/flights/{destination}/seasonality" threshold="1" />
        </Authorization>
    </RedApp>
</CFBundle>

Otherwise there will be an AUTH error response from 2SG.