In this lesson, the following topics are discussed:
- What is OData?
- Architectural constraints
- Tutorial: Learn about OData Fundamentals
What is OData?
In computing, Open Data Protocol (OData) is an open protocol that allows the creation and consumption of queryable and interoperable RESTful APIs in a simple and standard way. OData builds on HTTP, AtomPub, and JSON using URIs to address and access data feed resources. It enables information to be accessed from a variety of sources including (but not limited to) relational databases and file systems.
Architectural constraints
The following constraints must be fulfilled:
- Resource identification
- Fixed documents
- The service document
- The metadata document
- Dynamic resources
- Resource operation
- Querying
- Resource representation
The following are explanations about the constraints:
- Resource identification
OData uses URLs to identify resources. We use the following base URL with:
https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/
- Fixed documents
The following fixed resources can be found:
- The service document
The service document lists entity sets (collections), functions, and singletons that can be retrieved. Clients can use the service document to navigate the model in a hypermedia-driven fashion. The service document is accessed directly with the base URL: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/. Below is an example from a later exercise.
- The metadata document
The metadata document describes the types, sets, functions, and actions understood by the OData service. Clients can use the metadata document to understand how to query and interact with entities in the service.
The metadata document is available at: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/$metadata.
- Dynamic resources
The URLs for the dynamic resources may be computed from the hypermedia information in the service document and metadata document. The data feed for the ProductSet collection also contains links to other entities. The URL is as follows: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/ProductSet
- Resource operation
OData uses the HTTP verbs to indicate the operations on the resources. This is a REST aspect, as we have already seen.
- Querying
URLs requested from an OData endpoint may include query options. The OData protocol specifies various system query options endpoints should accept, these can be used to filter, order, map or paginate data. In the following, only the product with the product number HT-1000 is retrieved. The URL is: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/ProductSet('HT-1000')
- Resource representation
OData uses different formats for representing data and the data model. In OData protocol version 4.0, JSON format is the standard for representing data, with the Atom format still being in committee specification stage. For representing the data model, the Common Schema Definition Language (CSDL) is used, which defines an XML representation of the entity data model exposed by OData services.
Tutorial: Learn about OData Fundamentals
There is a fantastic tutorial Learn about OData Fundamentals with the following topics:
- Where OData came from and why it’s designed the way that it is.
- What the standard OData operations are and how they relate to HTTP.
- What the public Northwind OData service has to offer.
- What OData service documents and metadata documents describe.
- The basics of OData entity types, sets, and relationships.
It is recommend that you work through this tutorial to get fully acquainted with OData at SAP.
Summary
The OData protocol describes a RESTful Web API. In addition to the REST principles, it also offers other advantages that are particularly advantageous in the professional environment. The interface itself provides two meta documents, service and meta document. This comprehensively describes the interface. The most effective function is the ability to filter, search, and execute functions such as $count via query parameters on the interface. The representation takes place either in XML or JSON.