One of the holy grails in the IT community has been a universal vehicle for data exchange. Over the years there have been many technologies that have promised a solution, but it was never realized. Microsoft recognized the gap and developed the Open Data Protocol (OData) standard with other companies (IBM, SAP, etc.) backing the initiative. OData provides an abstract data model and protocol for data exchange. After all, Web services are just the public face of your internal data.
Last year's Microsoft TechEd conference included sessions on OData that piqued my interest, but I didn't get a chance to really dig into the technology until a recent project. Here is a quick tour of OData and how to use it.
Web services at REST
Before diving into OData, a quick refresher on Representational State Transfer (REST) is appropriate. REST is a set of design principles for building Web services that communicate resources and their states over HTTP to a vast number of available clients. It has mostly displaced the use of SOAP and WSDL alternatives due to its simplified approach. Some basic design principles of REST include that it is stateless; HTTP is the communication protocol along with XML and/or JSON being used to define/structure what is transferred. Uniform Resource Locators (URLs) are used to access elements, so a directory structure and IDs are used to identify resources -- everything has an ID to be easily identified. REST is a founding principle of OData.
What is OData?
The official OData site describes it as "a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today." It utilizes Web standards to expose and consume data -- that is, it utilizes REST. So, data elements or structure are exposed via URLs. Basically, OData provides a standard way or framework for designing and manipulating data using REST standards. For example, you may define data and its structure using JSON or ATOM.
Micorosft was once seen as an enemy of standards, preferring to go their own way, but this is no longer the case as demonstracted by OData and other Microsoft initiativesMetadata is a key aspect of OData; it provides a uniform way to define or describe data. It is the vehicle for communicating the relationships, types, and structure of the data
As previously stated, OData exposes data via URL paths that utilize directory structure and ID values to expose data elements. Let's take a quick look at how data is accessed using the REST approach. The basic element is the data service which is hosted, so the following URL points to the base URL for eBay's OData implementation:
With eBay, the base URL points to the actual OData Web service so it does not have to be specified. With the service known, you can access specific elements or a group of elements. We can build on the previous URL to get a collection of categories:
There are an overwhelming number of categories on eBay, but the Deals query is not overwhelming so you can see all of them. You can restrict the number of deals returned with the top query as the following example returns only the top 10 deals:
Also, you can view specific elements by using its key value:
One last example demonstrates getting the total count of items that will be returned:
These are a few examples of OData in the real world; the OData site provides complete details on all of actions and URL syntax that can be used to work with data.
The OData site provides client libraries for various languages that can be used to work with the OData protocol and data. There are libraries available for client access and for building services that expose data via OData; the libraries cover all major languages and the dominant mobile platforms. Complete coverage of each one is beyond the scope of this article, but future pieces will demonstrate programmatically processing OData elements. CodePlex provides tools for getting a feel for OData and how it works. A good example is the OData Viewer Tool, which provides a simple interface for perusing OData data sources like eBay.
A long journey
I am a bit jaded when it comes to Internet standards since I have seen so many come and go, but the fact that OData is actually being used gives me a good feeling about its future. A Microsoft press release from May 2012 demonstrates OData's acceptance. One positive aspect of OData that can only help it succeed is simplicity via the REST approach, a standard that is already widely used.
Microsoft was once seen as an enemy of standards, preferring to go its own way, but this is no longer the case as demonstrated by OData and other Microsoft initiatives.Keep your engineering skills up to date by signing up for TechRepublic's free Software Engineer newsletter, delivered each Tuesday.
Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a production environment on a daily basis.