OData and REST APIs: A comparison
Are you curious about what is REST and OData? Then, this article is for you. In it, you will find an explanation of what is REST, how it is applied to the construction of RESTful APIs; what is OData and how it is used to build web services, and the differences between the two.
Brief comparison
The table below summarizes the main similarities and differences between REST APIs and OData Services.
As the table shows, both technologies follow REST principles, although OData is more relaxed in that, if there is a good reason to avoid its use, it lets you do so.
Thus the OData Protocol is more comprehensive than the REST model, as in addition to the use of the REST principles, it provides a way to describe both the data and the data model.
So, let’s go deep into the details by explaining each of the concepts mentioned in the above table.
What is REST
Representational State Transfer, or better known as REST is a software architecture style, which defines a set of principles useful for creating efficient web services.
These principles were described by Roy Fielding in his doctoral dissertation written in 2000. As he stated during an interview:
“…That process honed my model down to a core set of principles, properties, and constraints that are now called REST”
In his dissertation Fielding identified six aspects of HTTP and HTML that made these technologies successful and efficient. These concepts or principles are:
- Client–server
- Stateless
- Cacheable
- Layered system
- Code on demand (optional)
- Uniform interface
- Identification of resources
- Manipulation of resources through these representations
- Self-descriptive messages
- Hypermedia as the engine of application state (HATEOAS)
The HTTP protocol is an example of a system that implements the principles of REST.
What is a REST API
A REST API is simply an Application Programming Interface that uses the above mentioned principles. Usually, they use XML or JSON to communicate, although the REST architecture doesn’t ask anything specific in this regard. Even more, REST doesn’t demand any particular format, and accepts any format that can be used via Content negotiation.
What is OData
OData or Open Data protocol is an application-level protocol that describes a way for interacting with data using RESTful services. At present it is in version 4.0. This latest version was standardized by OASIS and approved as an ISO/IEC International Standard.
Initially created by Microsoft in 2007, it was later released under the Microsoft Open Specification Promise, and thus made available to all.
The protocol is based on two main components:
- Industry standards: HTTP, XML, Atom and JSON.
- REST-based architecture: HTTP protocol.
However, the specification states that:
- OData must “follow REST principles unless there is a good and specific reason not to”.
- OData Services MUST support the ATOM encoding.
- OData services SHOULD support a JSON encoding.
Figure 2 shows the structure of an OData compliant web service. It rests on HTML technology, which somehow resolves the problem of being REST-based. In addition, it must include Atom encoding, which is based on the XML technology, and also adhere to the OData’s data handling specifications. Since version 4.0, OData also handles JSON.
OData uses Atom or JSON to define the data schema, and it provides two important models for the management of data. They are:
- Entity Data Model or EDM: it is an abstract data model that MUST be used to describe the data exposed by the service.
- Service Model: it consist of two static resources and a set of dynamic resources. The static resources provide a way to ask a service about its data model, and the dynamic ones offer methods to manage the data model.
The two static resources are:
- The metadata document, which describes the data model.
- The service document, which lists all of the top-level entity sets exposed by the service.
An important feature of the OData protocol is its support for a versioning scheme that enables services to be backward compatible.
In addition, there are several libraries that can be used to facilitate building and consuming OData-based services. Among them, Restier is the main library for the .NET framework, and Apache Olingo is the most important for the Java platform.
Conclusion
In this article we have seen what REST means, how it is used in RESTful APIs and in the OData Protocol. In addition, we have described the OData protocol’s main components.
We have concluded that REST is part of OData, and also more general. Thus, OData can be considered a safer guide to creating RESTful services.
We would be delighted to discuss your use case and explore how DBSync can support your success. Please feel free to Schedule a meeting with us.