Calculating... until our next FREE Code-Along Session. Secure your spot now

Build Your First Web App Today

Your 14-Day Free Trial Is Waiting To Be Activated
GET INSTANT ACCESS READ MORE ABOUT FIVE

OData vs. GraphQL: When to Use Which?

Avatar photo
Dominik Keller
Aug 2nd, 2024
Blog

OData vs. GraphQL: What is The Best Way to REST?

The Open Data Protocol, or OData, promotes itself as “the best way to REST”. A powerful and easy-to-use data access technology, it provides familiarity by combining the HTTP protocol with a SQL-like query language. How does OData compare against GraphQL, another data query and manipulation language for APIs?

Let’s find out in our OData vs. GraphQL comparison.



Code-Along: Develop an OData Data View in a Responsive Web App

Follow our step-by-step code-along tutorial and learn how to build a web app that connects to an OData service as a data source. This code-along guide is ideal for anyone building custom apps or software on an OData API.


What is OData?

OData was invented to make accessing data easier. It is a general-purpose data access technology developed by Microsoft, and lets developers query APIs or web services in SQL-like manner.

As a standard protocol based on HTTP, OData is the glue between clients, i.e. those requesting data, and data sources, i.e. those providing data. It enables applications to create, expose, and consume queryable APIs in a standard way.

If “standardized data access” sounds a lot like two other related technologies – JDBC and ODBC – it is. OData is similar to JDBC and ODBC and can replace them for most use cases.

OData: A Simple Example

Here is a simple scenario: say, you are a developer and you been tasked with building a portal on your company’s ERP system. How does the portal connect to the data stored in the ERP system? OData is the answer.

OData is very useful in custom application development, when a custom application, such as a portal, needs data access from an external, existing system.

With OData, the custom app doesn’t need direct database access. Everything happens through HTTP. However, unlike a standard API request, where a server responds with all the data, OData lets you query your data source. Developers can append “$filter” to a URL. The $filter determines what the server returns in its JSON response.

For example, a standard GET request for a list of airports would look like this:

GET serviceRoot/Airports

With OData, developers can specify which airport to return:

GET serviceRoot/Airports?$filter=contains(Location/Address, 'San Francisco')

OData provides a comprehensive library of string, date/time, and other operations that developers can use to filter data.

In summary, OData is a powerful, standardized, well-documented and easy-to-use data access technology. Not surprisingly, its (witty) team of inventors refers to it as “the best way to REST”.


What is GraphQL?

GraphQL is a query language for APIs developed by Facebook. It allows clients to request exactly the data they need, no more, no less.

Someone once said that “GraphQL is a fancy name for OData”. It is not. They are important differences between these two technologies, even though both are designed as data access technologies.

GraphQL is highly flexible and only needs a single endpoint. The query defines what data the client receives from said endpoint. It has an easy syntax too, but one that looks very different from OData.

To stick with our example about requesting a particular airport from a data source, here is what this would look like in GraphQL:

{
  airports(filter: { addressContains: "San Francisco" }) {
    id
    name
    location {
      address
    }
  }
}

This GraphQL query assumes that the schema has been set up to allow filtering by a substring.

The GraphQL response would be the same as OData’s by the way. Both would return a JSON file, such as this:

{
  "data": {
    "airports": [
      {
        "id": "1",
        "name": "San Francisco International Airport",
        "location": {
          "address": "San Francisco, CA"
        }
      },
      {
        "id": "2",
        "name": "Oakland International Airport",
        "location": {
          "address": "1 Airport Dr, Oakland, CA"
        }
      }
    ]
  }
}

GraphQL is a great technology to ensure your UI gets access to the right data.


OData vs. GraphQL: When to Use Which?

Now let’s compare OData vs. GraphQL: which technology works best for exposing and accessing data?

Why You Should Use OData

1. OData Is Easy to Implement:
All OData needs to work is a storage model. The technology works great for structured data (think relational databases). OData also exposes the underlying metadata, making it easier for clients to understand the structure of the data.

2. OData Works Great for CRUD Operations:
As a RESTful protocol with a standardized query language for the web, OData is very well suited for manipulating data with CRUD operations (Create, Read, Update, Delete). Its built-in query capabilties are very SQL-like and easy to read and write. OData, for example, supports filtering, ordering, aggregration, joining and paging.

3. When OData Is Supported.
At the risk of stating the obvious, it is worth adding that OData can of course only be used when it is natively supported. This applies to commonly used ERP systems (Dynamics or SAP), or custom apps developed in FileMaker, for example.


Why You Should Use GraphQL

1. GraphQL Gives Developers Flexibility:
GraphQL is highly flexible. Clients can request data from multiple sources in a single query, and they can specify exactly what fields they need, reducing over-fetching and under-fetching.

2. You Only Deal With a Single Endpoint:
GraphQL uses a single endpoint for all interactions, compared to multiple endpoints in REST. The queries define what data the client receives.

3. GraphQL is Well-Suited for Complex Data and Business Logic:
GraphQL is well-suited when more than just CRUD operations are required, and when a lot of business logic is involved. It works great for complex data structures or nested relationships.


Here Is What Developers Say About OData vs. GraphQL

OData is great if your consumer is a data grid – sorting, paging, filtering. GraphQL is great when your consumer is… unspecified – it’s a great way for consumers of a collection of APIs to get from them what they want. You handle mapping the relationships and retrieving the data from the APIs, the consumer can just browse it and pick what they want.” – Reddit

“OData indeed still has a place where it’s valuable: as an implementation detail, serving as a data access layer for internal forms-over-data applications dealing with dozens, hundreds, or thousands of CRUD screens.”Jeff Handley


Conclusion: OData vs. GraphQL

Use OData when you need a mature, standardized protocol with built-in query capabilities, particularly in Microsoft-centric environments or when dealing with applications that benefit from RESTful conventions.

Use GraphQL when you need flexibility in data querying, reduced over-fetching, and a more collaborative approach between frontend and backend teams. It’s ideal for modern web and mobile applications where responsiveness and efficiency are critical.


OData in Five

Five is a rapid application development environment that lets developers build and deploy bespoke business software faster. Five comes with native support for OData and it can easily treat any external application or web service that supports OData as a a data source. This, for example, includes common ERP systems such as Microsoft Dynamics and others. Five can simply fetch data from these systems and display said data in its (login-protected) front-end.

By using OData, Five does not need to store any data locally, but can be used as a UI front end builder on an OData data provider. Common use cases for Five are, for example, customer or business partner portals, where clients maintain information stored in Dynamics through a self-service web interface.

To learn more, sign up for a free trial.


Connect to OData, Build a Web App
Rapidly build and deploy custom software 




Start developing your first application!

Get Started For Free Today

Sign Up Free Book a demo

Build Your Web App With Five

200+ Free Trials Started This Week

Start Free

Thank you for your message!

Our friendly staff will contact you shortly.

CLOSE