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.
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:
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.
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.
Open the connector tab select the operation "Trips" and define the expression: i#[ Payload] at "Trips Search Request Reference."
Drag two Dataweave components to the flow, one in each side of the Google-QPX-Connector.
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.
Start the project and access the API 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.
Play with the API using de RAML Console and manipulate the request parameters to search for flights!!!
API Request example:
API response example:
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)