Introduction To OData

Introduction

OData (Open Data Protocol) is an open protocol for sharing the data. It is OASIS (Organization for the Advancement of Structured Information Standards) standard which defines best practice for building and consuming REST API.

The main goal of the Open Data protocol is to any application can able to access from any other application. Nowadays many applications like Web browsers, apps on mobile devices, BI tools are required to access common data sources. The data source of every application has its own approach and style so it is very difficult to create data source that can be accessed by all applications. Solution to this problem is to define common approaches and that all application owners agree to follow this approach for accessing the data.

OData is an extension of Atom and its defined specifying structured data. OData is standard and OData consumers are increasing every day.

Currently OData is widely used for exposing data. Application such as Facebook and eBay are exposing their data via OData. OData is preferred to use custom enterprise applications for expose data. To do this OData libraries are available for different application development platform such as .net and java. Cloud storage like Windows Azure and relational data in SQL Azure has built-in support for OData. Same as Content management software like SharePoint have built-in support for OData.

OData data source can be accessible by JavaScript code running on web browsers like IE, FF, etc. OData client library is also available for Silverlight applications and Other RIA (Rich Internet Applications). OData client libraries are available for Android, iOS and Windows phone. Many Bi tools support OData.

odata

Supported Output Formats of OData

OData supports following two different output formats,

  • Atom XML
  • Java Script Object Notation (JSON)

The following shows an example of an Atom XML,

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <feed xmlns="http://www.w3.org/2005/Atom">  
  3. <link href="http://example.org/feed/" rel="self" />  
  4. <link href="http://example.org/" />  
  5. <id>urn:uuid:78FFE95A-9AB4-4258-B46B-DF6F0A33A0D6</id>  
  6. <updated>2015-05-19T03:38:50Z</updated>  
  7. <entry>  
  8. <title>OData</title>  
  9. <link href="http://example.org/2003/12/13/atom03" />  
  10. <link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>  
  11. <link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>  
  12. <id>urn:uuid:89DC38BA-098F-4134-AE41-11246FD82997</id>  
  13. <updated>2015-05-19T03:38:50Z</updated>  
  14. <author>  
  15. <name>Test Users</name>  
  16. <email>[email protected]</email>  
  17. </author>  
  18. <content type="application/xml">  
  19. <m:properties>  
  20. <d:ID m:type="Int32">1</d:ID>  
  21. <d:ItemName>aa</d:ItemName>  
  22. <d:Description>aa item</d:Description>  
  23. <d:ReleaseDate m:type="DateTimeOffset">2015-05-19T03:38:50Z</d:ReleaseDate>  
  24. <d:DiscontinuedDate m:null="true"/>  
  25. <d:Price m:type="Double">25</d:Price>  
  26. <d:Rating m:type="Int16">3</d:Rating>  
  27. </m:properties>  
  28. </content>  
  29. </entry>  
  30. </feed>  
The following shows an example of JSON,
  1. {  
  2.    "@odata.context""http://services.odata.org/V4/OData/OData.svc/$metadata#Products",  
  3.    "value": [  
  4.      {  
  5.        "ID": 1,  
  6.        "Name""aa",  
  7.        "Description""aa Item",  
  8.        "ReleaseDate""2015-05-19T03:38:50Z ",  
  9.        "Rating": 2,  
  10.        "Price": 23  
  11.      },  
  12.      {  
  13.        "ID": 2,  
  14.        "Name""bb",  
  15.        "Description""bb Item",  
  16.        "ReleaseDate""2015-05-19T03:38:50Z",  
  17.        "Rating": 3,  
  18.        "Price": 3.5  
  19.      },  
  20.    ]  
  21. }  
The benefit of the JSON message format is it is very small in size and easy to understand compared to XML messages.

When to use OData

First question that is raisedis : Why do we use OData instead of SOAP based XML format? OData is new standard for communication and it is now accepted by most of clients. OData is now supported by .NET framework and Excel 2010 for Pivot Table. We can also run LINQ query on OData service from client code. Many BI tools support OData data source. It is also able to expose data from relational database, file systems, services, etc.

So, OData provides a common way for clients to access data source. It also allows us to write service once and many clients can use this data differently.

Read more articles on OData (Open Data Protocol):


Similar Articles