Technology Spotlight: Introducing RapidQL
/What if you could harness the power of queries without making multiple round trips? Alex Walling and the folks over at RapidAPI have answered just that. The development team has churned out a powerful new addition to the query language lineup—dubbed RapidQL.
RapidQL aims to “reduce glue code and improve performance by writing just one query to fetch and transform data into a format your app can work with.” How exactly is this accomplished? We’ll dive into the technical details and uncover the story behind RapidQL’s development.
Playing “Fetch” Just Became Much More Fun
RapidQL excels at unlocking the power of multiple APIs simultaneously. The language incorporates nesting to process multiple inputs with one request. This makes it easy to extract data from different sources simultaneously. Additionally, returned data can be used concurrently to form subsequent queries.
Developers can assemble complex commands without too much heavy lifting. Similar operations took much longer to create in the past. Developers made some key concessions:
Code swelled in size since queries took many more lines to write
Efficiency suffered to a degree from this increased workload
Performance wavered as numerous round trips were added to call equivalent data sets
RapidQL allows programmers to avoid these pitfalls. As apps and their dependencies grow ever more complex, a clear need for simplification has emerged. This is a capable solution.
Identifying Use Cases
RapidQL’s potential is vast. It integrates seamlessly with the company’s marketplace of over 10,000 public APIs. RapidQL itself is an open-source project, making this a perfect pairing.
Alex Walling, Head of Developer Relations at RapidAPI, summarized this nicely:
RapidQL can handle a diverse set of applications. However, it truly shines in three areas: data enhancement, database and API data mergers, and querying microservices. The language plays nicely with large CSV files and enriches them granularly using APIs. Such APIs can be used to grab table data and gather user-specific statuses (think FedEx orders). One query can get this done. RapidQL can also reference API collections, subsets of specific APIs, and any relevant analytics.
If your application relies on databases like MySQL, PostgreSQL, and MongoDB, fear not! Support is up and running. Simply add your database’s connection details to your RapidQL initialization. RapidQL queries can utilize counts and averages, among other computations. These are applied to the next query.
Developers can use RapidQL to build simple or complex apps. The business value proposition is strong, as are the technical advantages. Let’s examine the latter a little closer.
Technical Foundations
RapidQL is built using JavaScript, relying primarily on the PEG.js library for parser generation. This essentially helps describe the various inputs used in your queries. PEG helps convert RapidQL queries into an execution tree. RapidQL itself uses grammar written by its creators, bucking the schematic approach seen in cousins like GraphQL. This was one of the trickiest technical hurdles to overcome in RapidQL’s development, but the results have been impressive.
Why use JavaScript as a backbone? According to Walling, easy concurrency is indispensable. Using JavaScript allows developers to run multiple overlapping operations out of sequence, without impacting the final result. This has similar benefits to using async in programming. Which leads us to our next topic: promises.
RapidQL uses Promise.all to execute numerous query strings together. These promises can only succeed or fail once, as well. Baking callbacks into the language makes status monitoring easier. Developers can form correct callbacks pretty easily. This is important when dealing with data—especially since RapidQL queries are outcome driven. This allows for the following:
Performance gains with relatively little effort
Network-based—not CPU-based—heavy lifting
By comparison, opting for languages like Python or Java would introduce more hassle. It’s easier to make API requests and execute all children in the tree simultaneously with Rapid’s implementation. Any contextual considerations in the queries are handled by Object.assign and optimized via Proxy() objects. This is crucial for larger, nested queries.
Handling External APIs
The depth of the query tree has the biggest impact on performance. RapidAPI tells us that three nested queries will perform the same when ran over one or one hundred users. How APIs and databases are configured will influence execution to a degree. Thankfully, RapidQL is flexible if an “API is RESTful and returns JSON data.” Walling also shared that support for automatic XML-to-JSON conversions is coming.
Getting Started with RapidQL
It’s pretty easy to jump into RapidQL development. Installation is breeze and kick-started via npm install rapidql. Developers can then test their RapidQL imports using the PEG.js online parser tester (thanks, Alex!).
We’ve also touched on the language’s integration with the RapidAPI marketplace. That library clearly displays the structure and endpoints of compatible, public APIs. You can quickly convert any snippet into its RapidQL counterpart via dropdown menu. Rapidly copy this into any code manager to start experimenting. Playing around with your queries lets you consolidate API responses.
The RapidQL team presented us with a great example. Say you want to take an IP address and pinpoint its location. You can integrate a geolocation API to reveal this location, then use a weather API to get current conditions for that city. This is one way to design a multistep query. We can use many other API combinations to achieve similar results. RapidQL ensures we only pull what’s needed for our specific applications.
Final Thoughts
RapidQL is a fresh, performant approach to tackling some of our most demanding requests. The technology marries databases and APIs beautifully. Perhaps most exciting is that there’s much more to come for RapidQL—the roadmap promises to bring many new enhancements, especially as users keep catching on. We’re thrilled to monitor its progress!
Want to get involved with RapidQL’s development? The project is 100% open source, and the team invites contributions from anyone interested. You can check out RapidQL’s documentation here and get a feel for the language. A project board is posted on GitHub, and the company is eager to incorporate even more integrations. Happy programming!