Presentamos los enlaces

¿Qué es un enlace?

Rapid API está formado por varios recursos de API que te permiten crear una experiencia de reserva integral para los viajeros. Estos recursos se usan en secuencia para construir transacciones completas, como buscar, consultar precios, reservar y gestionar reservas.

Para agilizar estas transacciones de varios pasos, Rapid API emplea una eficaz herramienta llamada Link.

Un Link es una referencia a un recurso relacionado, que actúa como una guía que dirige a los desarrolladores al recurso de API pertinente siguiente que es necesario para progresar sin problemas en la transacción.

Los desarrolladores pueden aprovechar los enlaces de operaciones anteriores en SDK Rapid para crear y ejecutar rápidamente nuevas operaciones, sin tener que pasar por el proceso de configuración habitual y mejorando significativamente la eficiencia.

Information

Nota

Esta función está disponible en rapid-sdk v4.3.0 y en versiones posteriores.

¿Por qué conviene utilizar un enlace?

Un Link es una forma cómoda de navegar por las operaciones de Rapid API sin tener que crear manualmente la operación siguiente. Puedes extraer un Link de la respuesta de la operación anterior y utilizarlo para crear la operación siguiente.

Saca partido de los enlaces como se indica a continuación:

  • Ahorra tiempo: puedes configurar los parámetros de la solicitud y la operación para no tener que crear manualmente la operación siguiente.
  • Simplifica el proceso: puedes navegar fácilmente por las operaciones de Rapid API utilizando el Link de la operación anterior, para no tener que extraer manualmente la información necesaria.
  • Reduce los errores: con Link, puedes evitar los errores que podrían producirse al crear manualmente la operación siguiente.

¿Cómo se usa un enlace?

Para obtener un Link, tienes que extraerlo de la respuesta de la Operation anterior. A continuación, puedes crear la Operation siguiente a partir del Link y ejecutarlo con RapidClient.

Por ejemplo, puedes crear un Link a partir de la respuesta de GetAvailabilityOperation y utilizarlo para crear 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 priceCheck link from PropertyAvailability operation (Here, we select the first rate for the first room, then get the priceCheck link)
Link 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);
// ...

Otro ejemplo sería crear un Link a partir de la respuesta de PriceCheckOperation y utilizarlo para crear una reserva.

// 1. Get the RoomPriceCheck from the previous step
RoomPriceCheck roomPriceCheck = roomPriceCheckResponse.getData(); // from the previous step

// 2a. Extract the Link from the RoomPriceCheck
Link 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();

Para obtener más ejemplos sobre cómo utilizar un Link, consulta la sección Ejemplos de uso .

¿Te ha resultado útil esta página?
¿Cómo podemos mejorar este contenido?
�Gracias por ayudarnos a mejorar!