링크 사용
개요
Rapid는 여행객을 위한 end-to-end 예약 환경을 구축하기 위해 함께 사용되는 여러 API 리소스로 구성되어 있습니다. 이러한 리소스를 순서대로 활용하여 쇼핑, 가격 확인, 예약, 그리고 마지막으로 **예약 관리와 같은 완전한 트랜잭션을 구축할 수 있습니다 **.
이러한 여러 단계로 이루어진 트랜잭션을 간소화하기 위해 Rapid는 ‘링크’라는 강력한 도구를 사용합니다.
링크는 관련 리소스를 가리키는 참조로, 개발자가 트랜잭션을 원활하게 진행하기 위해 필요한 다음 관련 API 리소스로 안내하는 역할을 합니다.
개발자는 링크를 활용함으로써 일반적인 설정 과정을 거치지 않고도 새로운 작업을 신속하게 생성하고 실행할 수 있어 효율성을 크게 높일 수 있습니다.
링크 사용의 장점
링크를 사용하면 다음 작업을 수동으로 생성할 필요 없이 Rapid API 작업 간을 편리하게 이동할 수 있습니다. 각 응답의 ‘ links ’ 섹션에 링크가 정의되어 있습니다. 이전 작업의 응답에서 링크를 추출하여 이를 활용해 다음 작업을 생성할 수 있습니다.
링크를 사용하면 다음과 같은 이점이 있습니다:
- 시간 절약: 요청 매개변수와 작업을 직접 설정하여 다음 작업을 수동으로 생성할 필요가 없습니다.
- 절차를 간소화합니다: 필요한 정보를 수동으로 추출할 필요 없이, 이전 작업의 링크를 사용하여 Rapid API 의 작업들을 손쉽게 탐색할 수 있습니다.
- 오류 감소: 링크를 사용하면 next 작업을 수동으로 생성할 때 발생할 수 있는 오류를 방지할 수 있습니다.
링크는 어떻게 사용하나요?
작업 응답에서 반환된 ‘ links ’ 섹션을 찾아 해당 링크를 사용하여 다음 적절한 작업을 구성하십시오. 그런 다음 operation에서 다음 link를 생성하고 RapidClient를 통해 이를 실행할 수 있습니다.
예를 들어 GetAvailabilityOperation의 응답에서 PriceCheckOperationLink를 생성하 고 이를 PriceCheckOperation 생성에 사용할 수 있습니다.
// 1. Create and execute the GetAvailabilityOperation (The first operation)
GetAvailabilityOperation getAvailabilityOperation = new GetAvailabilityOperation(getAvailabilityOperationParams);
Response<List<Property>> propertiesResponse = rapidClient.execute(getAvailabilityOperation);
// 2a. Select the needed property from the response (Here, we select the first property)
Property property = propertiesResponse.getData().get(0);
// 2b. Make sure the property is an instance of PropertyAvailability
if (!(property instanceof PropertyAvailability)) {
return;
}
PropertyAvailability propertyAvailability = (PropertyAvailability) property;
// 3a. Extract the PriceCheckOperationLink from PropertyAvailability operation (Here, we select the first rate for the first room, then get the PriceCheckOperationLink)
PriceCheckOperationLink priceCheckLink = propertyAvailability.getRooms().get(0).getRates().get(0).getBedGroups().entrySet().stream().findFirst().get().getValue().getLinks().getPriceCheck();
// 3b. Create the needed context for the PriceCheckOperation
PriceCheckOperationContext priceCheckOperationContext = PriceCheckOperationContext.builder().customerIp("1.2.3.4").build(); // fill the context as needed
// 4. Create and execute the PriceCheckOperation using the Link
PriceCheckOperation priceCheckOperation = new PriceCheckOperation(priceCheckLink, priceCheckOperationContext);
Response<RoomPriceCheck> roomPriceCheckResponse = rapidClient.execute(priceCheckOperation);
// ...또 다른 예는 PriceCheckOperation의 응답에서 PostItineraryOperationLink를 생성하고 이를 예약 생성에 사용할 수 있습니다.
// 1. Get the RoomPriceCheck from the previous step
RoomPriceCheck roomPriceCheck = roomPriceCheckResponse.getData(); // from the previous step
// 2a. Extract the Link from the RoomPriceCheck
PostItineraryOperationLink postItineraryLink = roomPriceCheck.getLinks().getBook();
// 2b. Create the needed context for the PostItineraryOperation
PostItineraryOperationContext postItineraryOperationContext = PostItineraryOperationContext.builder().customerIp("1.2.3.4").build(); // fill the context as needed
// 2c. Create the CreateItineraryRequest
CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder().build(); // fill the request as needed
// 3. Create and execute the PostItineraryOperation using the Link
PostItineraryOperation postItineraryOperation = new PostItineraryOperation(postItineraryLink, postItineraryOperationContext, createItineraryRequest);
// 4. Execute the PostItineraryOperation
Response<ItineraryCreation> itineraryCreationResponse = rapidClient.execute(postItineraryOperation);
ItineraryCreation itineraryCreation = itineraryCreationResponse.getData();