Open Data Protocol

Open Data Protocol (OData) is a RESTful data access protocol initially defined by Microsoft. Versions 1.0, 2.0, and 3.0 are released under the Microsoft Open Specification Promise. Version 4.0 was standardized at OASIS,[1] with a release in March 2014.[2]

The protocol enables the creation and consumption of REST APIs, which allow resources, identified using URLs and defined in a data model, to be published and edited by Web clients using simple HTTP messages. It shares some similarity with JDBC and ODBC but OData is not limited to relational databases.

Implementations

It is the data API for Microsoft Azure. SAP NetWeaver Gateway[3] provides OData access to SAP Business Suite and SAP Business Warehouse. IBM WebSphere eXtreme Scale REST data service can be accessed by any HTTP client using oData.[4] OData client implementations include Microsoft SharePoint 2010, WCF Data Services[5] and Windward Reports.[6]

Architecture

OData is built on the AtomPub protocol and XML where the Atom structure is the envelope that contains the data returned from each OData request. An OData request uses the REST model for all requests. Each REST command is a POST, GET, PUT, PATCH, or DELETE HTTP request (mapping to CRUD) where the specifics of the command are in the URL.

Any platform that provides support for HTTP and XML is enough to form HTTP requests to interact with AtomPub. The OData specification defines how AtomPub is used to standardize a typed, resource-oriented CRUD interface for manipulating data sources.

Functionality

Fundamentally OData extends AtomPub with a data model for defining typed or untyped values on an entity (e.g. columns in a row) and adds a query language for getting just the entity and the data requested.

The following examples use the sample OData datasource located at http://services.odata.org/OData/OData.svc. This URI is the root URI for the data source offered via the OData protocol. All requests are extensions of this URI.

Metadata

OData provides full metadata of the datasource. With a $metadata query it is possible to see the full structure of the data available from a given OData service, as well as data types, relationships, etc.

The document returned from the OData $metadata operation is defined by the “Entity Data Model for Data Services Packaging Format” specification which is a small document that says it’s the Schema element under the Edmx and DataServices elements. That Schema element and everything inside it is the “Conceptual Schema Definition File Format” specification, normally called the “CSDL spec” (or Conceptual Schema Definition Language specification). CSDL defines Microsoft’s Entity Data Model (EDM), which is also the data model of OData. The CSDL specification describes how to interpret the result of the $metadata operation to see what kind of data is being exposed by the OData service.

Partial metadata for http://services.odata.org/OData/OData.svc/$metadata (duplicate element types removed):

  1. <?xml version="1.0" encoding="utf-8" standalone="yes"?>
  2. <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  3.     <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="2.0">
  4.         <Schema Namespace="ODataDemo" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
  5.             <EntityType Name="Product">
  6.                 <Key>
  7.                     <PropertyRef Name="ID"/>
  8.                 </Key>
  9.                 <Property Name="ID" Type="Edm.Int32" Nullable="false"/>
  10. ...
  11.                 <NavigationProperty Name="Category" Relationship="ODataDemo.Product_Category_Category_Products" FromRole="Product_Category" ToRole="Category_Products"/>
  12.                 <NavigationProperty Name="Supplier" Relationship="ODataDemo.Product_Supplier_Supplier_Products" FromRole="Product_Supplier" ToRole="Supplier_Products"/>
  13.             </EntityType>
  14.             <EntityType Name="Category">
  15. ...            
  16.             </EntityType>
  17.             <EntityType Name="Supplier">
  18.                 <Property Name="Address" Type="ODataDemo.Address" Nullable="false"/>
  19. ...                
  20.             </EntityType>
  21.             <ComplexType Name="Address">
  22.                 <Property Name="Street" Type="Edm.String" Nullable="true"/>
  23. ...                
  24.             </ComplexType>
  25.             <Association Name="Product_Category_Category_Products">
  26.                 <End Role="Product_Category" Type="ODataDemo.Product" Multiplicity="*"/>
  27.                 <End Role="Category_Products" Type="ODataDemo.Category" Multiplicity="0..1"/>
  28.             </Association>
  29. ...            
  30.             <EntityContainer Name="DemoService" m:IsDefaultEntityContainer="true">
  31.                 <EntitySet Name="Products" EntityType="ODataDemo.Product"/>
  32.                 <EntitySet Name="Categories" EntityType="ODataDemo.Category"/>
  33.                 <EntitySet Name="Suppliers" EntityType="ODataDemo.Supplier"/>
  34.                 <AssociationSet Name="Products_Category_Categories" Association="ODataDemo.Product_Category_Category_Products">
  35.                     <End Role="Product_Category" EntitySet="Products"/>
  36.                     <End Role="Category_Products" EntitySet="Categories"/>
  37.                 </AssociationSet>
  38. ...                
  39.                 <FunctionImport Name="GetProductsByRating" EntitySet="Products" ReturnType="Collection(ODataDemo.Product)" m:HttpMethod="GET">
  40.                     <Parameter Name="rating" Type="Edm.Int32" Mode="In"/>
  41.                 </FunctionImport>
  42.             </EntityContainer>
  43.         </Schema>
  44.     </edmx:DataServices>
  45. </edmx:Edmx>

CSDL defines the usual primitive types which are the same types found in .NET DbTypes enum.

CSDL defines a Navigation element references a corresponding Association, which defines the nature of the relationship between two entity types. In most cases, the important part is the multiplicity defined on both ends.

To get to the related products, follow the relative URL in the href to a feed document which can have any number of products in it.

The properties in the content element map to properties on the entity type and what types each of the properties is. If it’s not specified, the default type is Edm.String.

Read

OData provides functionality to form URLs based on what you know (and can discover) about the underlying data. For example, you can start at the top level service document and keep drilling in.

A very simple query is http://services.odata.org/OData/OData.svc/Categories(0) which returns the first Category in the data source:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xml:base="http://services.odata.org/OData/OData.svc/" 
   xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
   xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <id>http://services.odata.org/OData/OData.svc/Categories(0)</id>
  <title type="text">Food</title>
  <updated>2012-08-26T16:38:13Z</updated>
  <author>
    <name />
  </author>
  <link rel="edit" title="Category" href="Categories(0)" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products" 
      type="application/atom+xml;type=feed" 
      title="Products" href="Categories(0)/Products" />
  <category term="ODataDemo.Category" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <m:properties>
      <d:ID m:type="Edm.Int32">0</d:ID>
      <d:Name>Food</d:Name>
    </m:properties>
  </content>
</entry>

You can do more than request a single dataset.You can request more (multiple datasets), less (a single value), and links to associated data.

Client libraries

There are a number of OData client libraries available to access OData:

More libraries are listed at the OData.org site.

Server libraries

There are a number of OData server libraries available to publish OData:

More libraries are listed at the OData.org site.

Applications

Tools

See also

References

External links