Wednesday, December 2, 2020

Standard query language for your Web API, why GraphQL and OData?

GraphQL

GraphQL created by Facebook in 2012 and released publicly in 2015. I get the following definition of GraphQL from Wikipedia:
GraphQL is an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.
In my opinion, the killer feature of GraphQL is in the data query side instead of data manipulation, as REST API have good enough capability of data manipulation. The following is the key reasons I adopted GraphQL in my Web API:
  • Client applications of limited network bandwidth and latency is critical such as mobile application get to choose what fields of object graph (a hierarchical structure of related objects) need to be included in the response.
  • Client applications can inspect the schema of GraphQL API via its introspection capability. Development tools of strongly-type programming language such as Java, Dart, Go, etc. can generate client code via GraphQL introspection, it will greatly improve the productivity of developers.
Updated on Dec 17: You can find out more from a GraphQL API implemented by me in the following blog post: 

OData

OData created by Microsoft in 2007. I get the following definition of OData from Wikipedia:
Open Data Protocol (OData) is an open protocol that allows the creation and consumption of queryable and interoperable REST APIs in a simple and standard way.
In a blog post published by Progress, it has better definition of OData:
OData advocates a standard way of implementing REST APIs that allows for SQL-like querying capabilities using these RESTful APIs. OData is essentially SQL for the web built on top of standard protocols – HTTP, JSON & ATOM XML – while leveraging the REST architecture style.
In my opinion, benefits of OData is similar to GraphQL with the following differences:
  • OData supports schema discovery by query the metadata directly with $metadata URL without introspection.
  • OData supports ATOM XML and JSON response.
  • OData has been adopted by a lot of technologies and companies including SAP, IBM, Salesforce, Tableau, Databoom, Progress, Red Hat and Dell especially in spreadsheet, analytics, reporting, dashboard and business intelligence applications.
Updated on Dec 30: You can find out more from a OData API implemented by me in the following blog post: 

What do you think? I'd love to hear from you. :)

Like this blog?

Thanks for visiting! If you like what you see, I'd really appreciate you linking to it or otherwise sharing it with people you think would find it useful.

No comments: