The era of smart devices and apps has transformed the way application integrations work. Such integrations needs to be performed mostly with limited memory and constrained bandwidth environments. For a long time, REST was the choice for these integrations because of its simplicity. There is no doubt that REST has simplified integrations. But consumers of the APIs have no way to control the size and shape of the API response. Moreover, REST is based on the principle of resources; if a consumer needs data from two different resources, two separate requests go to the server.
Figure 1: REST API client requesting data from multiple sources
This is the problem API-querying technologies like GraphQL and OData are trying to address. API-querying technologies enable API users to query only the information required from multiple data sources with a single request. These technologies expand the idea of SQL to the web APIs by exposing the complete business Object to consumers – providing them the ability to query what they need by declaring the fields and conditions in the API request. Only the information that a consumers requested is returned in the single API response. This means no over-fetch, no under-fetch – only the precise information requested is retrieved.
Figure 2: Client requesting data from multiple sources using GraphQL/OData
These technologies help applications that run on devices and the front-end to offer the best user experience in low CPU and low bandwidths, rather than spending computing resources for processing heavy response data. However, API querying is not just restricted to a front-end layer; it can be applied to any layer of the enterprise.
Wipro helped one of the largest financial institutions in the US to modernize its legacy application stack using GraphQL. The financial leader was running an application on the mainframe and wanted to gradually migrate to reduce the recurring cost of MIPS on the mainframe. The customer selected Cassandra as the target data platform and exposed data APIs on this platform.
Wipro leveraged these data APIs to build GraphQL-enabled Springboot microservices for customer profile, express consent, and more. The benefits to the financial leader not only included lean and clean API use, but also a simplified architecture by aggregating multiple data APIs and presenting the data as a single business object for use by internal and external applications.
When to Use API Querying or REST
API querying is a good option when –
- Consumer needs to have control of the response data
- When there are bandwidth concerns
- Aggregation of data required from multiple sources
- Need to control network costs by regulating the data flow
That doesn’t mean REST is going away. Certain high-performance queries need to be addressed by REST to avoid an additional layer of API query. In addition, REST also provides a robust framework based on HTTP, which is easily comprehensible to both machines and humans. However, API query is an intuitive way to fetch exactly the information requested.