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 |
---|
Type Parameteres:
Returns: |
sendExternal |
Type Parameters:
Returns: |
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.