Integrating Google QPX With Mule

Editor's note: This article was submitted by one of our readers under our Contributed Content program. It originally appeared on DZone and is being published here with the author's permission. With the recent announcement that Google plans to retire the QPX Express API, it may be worth looking into alternatives. Some options include APIs from Fareportal, Skyscanner and Skypicker.

The Google QPX Express API allows developers to search for real flight availability and prices and use this data into their applications. Google Flights use this same data to provide a flight search and travel insights into Google search.

Recently, I developed a community connector using Mule DevKit allowing a better and easier integration for Mule developers. This connector interacts with Google QPX API, providing a flight search operation and allows DataSense metadata, consequently improving the integration with Mule using Dataweave.

In this article, I'll present this connector building an application to define an API using RAML to search for flights and transforming data using Dataweave.

The project is published on GitHub and you could access the connector documentation here.

First of all, let's install the connector:

Clone or download the Github repository and import the project into Anypoint Studio with File--> Import--> Anypoint Connector Project from External Location.

Right-click the imported project and choose Anypoint Connector--> Install or Update.

After the installation, the connector will be available on the Anypoint Studio palette.

The RAML API is defined with a unique resource: GET /air/search and query parameters as follow:

code: RAMP API definition search query

The response (Recommendation array) is defined using RAML Types. See the complete RAML definition below for details.

Create a new Mule project and use this RAML definition to obtain auto-generated flows for the API.

Create a new Mule configuration file to implement the API. Create a new flow and reference it on auto-generated air/search flow.

create flow

In the new flow, drag the Google-QPX-Connector from your palette and create a new configuration to the connector. You need to specify a valid API Key, see this link to obtain a new one.

Click "Test connection..." to validate the API Key and check if everything is ok with your configuration.

connector configuration

Open the connector tab select the operation "Trips" and define the expression: i#[payload] at "Trips Search Request Reference."

connector definition

Drag two Dataweave components to the flow, one in each side of the Google-QPX-Connector.

implementation flow

In the first one, code the request transformation using the air/search resource parameters previously defined in the RAML. This will create a minimum request data to query Google QPX API.

code: minimum request data to query

Start the project and access the API console:

http://localhost:8081/console

In the last one, code the response transformation previously defined in the RAML air/search resource. This will convert the response data from Google QPX API to the RAML response type.

code: convert the response data

Play with the API using de RAML Console and manipulate the request parameters to search for flights!!!

RAML console

API request example:

RAML console request

API response example:

RAML console response

The complete project can be found on the GitHub repository in the demo folder.

This is a simple example of how to play with Google QPX Express and could help you to start a new project relating to travel content.

Please feel free to get in touch if you have any doubts or ideas!

(Disclosure: MuleSoft is the parent company to ProgrammableWeb)

Guilherme Pereira
 

Comments