What's New With OData 4: OData 2 vs. OData 4
What's New With OData 4: OData 2 vs. OData 4
OData 4 differs significantly from OData 2. Learn about the differences between them when using Hybrid Data Pipeline and decide whether you need OData 2, OData 4 or both.
Join the DZone community and get the full member experience.Join For Free
How to Simplify Apache Kafka. Get eBook.
OData (Open Data Protocol) defines a set of best practices for building and consuming RESTful APIs. OData is very popular and has been adopted by many technologies and companies including SAP, IBM, Salesforce, Tableau, Databoom, Progress, Red Hat, and Dell. If you'd like to learn the basics of OData, see our OData FAQs.
Progress is proud to serve on the OData Technical Committee. In fact, we were one of the original members of this committee, along with other technical giants such as IBM, Microsoft, SAP, Redhat, CA, and Citrix. We offer Hybrid Data Pipeline, the industry's first vendor-agnostic data gateway, which lets you OData-enable your data source through simple clicks.
10 Major Differences Between OData 2 and OData 4
As you consider enabling your application or data source with an OData endpoint, you will invariably ask yourself if you should use OData 2, OData 3, or the latest OData 4 version. While OData 3 and OData 2 are very similar, OData 4 is drastically different from OData 2. With the latest release, Hybrid Data Pipeline can help you produce both OData 2 as well as OData 4 from your data sources. Understanding the differences between these endpoints from Hybrid Data Pipeline can help you decide if you need OData 2, OData 4, or both.
- OData 2 was a Microsoft Open Specification Promise (OSP), while OData 4 is approved by OASIS and ISO. While developers were apprehensive about adopting OData 2, we are observing more adoption for OData 4.
- According to the OData 2 specification, payload had to be retrieved in both XML and JSON formats. In OData 4 however, XML is optional. So, Hybrid Data Pipeline today supports both XML and JSON in OData 2 and only JSON in OData 4. However, the metadata can still be retrieved in the XML format in OData 4.
- In OData 4, the JSON data format now allows you to control the amount of metadata that is returned in query responses. There are three levels of metadata supported:
- Full: The response contains all the metadata needed to describe the response.
- Minimal: The response metadata references the metadata document. Information in the metadata document is not repeated in the response.
- None: The response contains no metadata. The application must understand the response structure.
- Hybrid Data Pipeline supports batch requests in OData 4 only. Batch requests allow you to submit multiple operations in the form of a single endpoint request. Operations are submitted in the HTTP request payload and can include individual requests and changesets. (For more information on batch requests, see this article.)
- OData 4 adds a new flexible search capability,
$search. The search feature allows you to query a collection for entities that match a specified search expression. Unlike the existing filter capability, which allows a query to specify that a specific property or properties match certain criteria, the search feature can apply the search expression to any of the properties of an entity. Hybrid Data Pipeline extends this feature to OData 2 as well using the
$expandsystem query option has been enhanced in OData 4. This feature specifies the related resources to be included in line with retrieved resources. In OData 2, if a single value navigation property is expanded, you get all the properties of the entity if it was a single value navigation property. And if a collection navigation property is expanded, you get all of the entities in the collection and all of the properties of those entities. In OData 4, you can now refine the results using the
- When doing an update there are two ways to update an entity: replace the definition of the entity with a new entity (Replace semantics). Or, you can change individual properties of an existing entity (Edit semantics). The HTTP
PUTmethod is used to update an entity with Replace semantics. In OData 4, the standard HTTP
PATCHmethod is used to update an entity with Edit semantics. OData 2 used the non-standard
MERGEHTTP method for updates with Edit semantics.
$inlinecountin OData 4.
$counthas been enhanced to be used with
- Changes in support for data types in OData 4:
DateTimehas been deprecated. The lack of timezone information in OData 2 causes significant problems. Use DateTimeOffset instead.
Edm.Timehas been replaced with
Edm.TimeOfDayto make it clear whether it is the duration of a specific time of day.
Edm.Datehas been added as there was no way to express just a date in OData 2.
Edm.Floathas been eliminated.
All these and many other enhancements in OData 4 give a significant performance boost to your application compared to OData 2. You can learn about the other differences in this article from OASIS.
Support OData 2 and/or OData 4 With Hybrid Data Pipeline
Due to the significant changes in the way these frameworks are defined, you'll need different clients to consume both the OData 2 and OData 4 endpoints. Thanks to all the latest changes, OData 4 shows significant performance improvement compared to OData 2. While some functions have been replaced and enhanced, some of them have been deprecated — for example, support for the XML Data Format.
If you're building an application for the modern ecosystem, OData 4 is a no-brainer as it gives you a significant performance boost. However, some existing applications need OData 2 or an XML payload. For that reason, you should leverage Hybrid Data Pipeline, which supports both interfaces without any coding at all.
Published at DZone with permission of Nishanth Kadiyala , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.