Using links

Overview

Rapid consists of several API resources used together to create an end-to-end booking experience for travelers. You use these resources in sequence to build complete transactions, such as shopping, price checking, booking, and, finally, managing bookings.

To streamline these multistep transactions Rapid uses a powerful tool called links.

A link is a reference to a related resource, acting as a guide that directs developers to the next relevant API resource needed to seamlessly progress through the transaction.

By leveraging links, developers can swiftly create and execute new operations, bypassing the typical set up process and significantly enhancing efficiency.

Information

Note

This feature is available in the rapid-sdk v5.1.0 and later.

A link is a convenient way to navigate through the Rapid API operations without having to manually create the next operation. Links are defined in the links section of each response. You can extract a link from the response of the previous operation and use it to create the next operation.

Using a link offers the following benefits:

  • Saves time: You don't have to manually create the next operation by setting up the request parameters and the operation.
  • Simplifies the process: Easily navigate through the Rapid API operations by using the link from the previous operation, without having to manually extract the information needed.
  • Reduces errors: By using a link, you can avoid errors that might occur when manually creating the next operation.

How to use a link?

In an operation response, look for the returned links section then use the link to build the next suitable operation. Youu can then create the next operation from the link and execute it with the RapidClient.

For example, you can create a PriceCheckOperationLink from the response of a GetAvailabilityOperation and use it in creating a 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);
// ...

Another example would be to create a PostItineraryOperationLink from the response of a PriceCheckOperation and use it in creating a booking.

// 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();

For more examples on how to use links, see the Usage Examples section.

Did you find this page helpful?
How can we improve this content?
Thank you for helping us improve!