Skip to content

Instantly share code, notes, and snippets.

@nuwanbando
Created February 17, 2020 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuwanbando/baa4999989615d659626e6b58baf5e47 to your computer and use it in GitHub Desktop.
Save nuwanbando/baa4999989615d659626e6b58baf5e47 to your computer and use it in GitHub Desktop.
function bookAirline(http:Caller caller, map<json> outReqPayload, json | error airlinePreference, http:Response outResponse) returns error? {
// Reserve airline ticket for the user by calling Airline reservation service
// construct the payload
map<json> outReqPayloadAirline = outReqPayload.clone();
outReqPayloadAirline["Preference"] = <json>airlinePreference;
// Send a post request to airlineReservationService with appropriate payload and get response
http:Response inResAirline = check airlineReservationEP->post("/reserve", <@untainted>outReqPayloadAirline);
// Get the reservation status
var airlineResPayload = check <@untainted>inResAirline.getJsonPayload();
string airlineStatus = airlineResPayload.Status.toString();
// If reservation status is negative, send a failure response to user
if (airlineStatus != "Success") {
outResponse.setJsonPayload({
"Message": "Failed to reserve airline! " +
"Provide a valid 'Preference' for 'Airline' and try again"
});
var result = caller->respond(outResponse);
if (result is error) {
log:printError(result.reason(), err = result);
}
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment