Introducing OData

Objectives

After completing this lesson, you will be able to:

  • Introduce OData

Introduction to OData

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.

Explore the APIs From the SAP Gateway Demo System

Business Scenario

In this exercise, we will examine the GWSAMPLE_BASIC service. This sample service is based on the Enterprise Procurement Model (EPM). We want to use the APIs directly to find the customerID and the associate address data for the product ID HT-1000.

Documentation of GWSAMPLE_BASIC: Sample Service - Basic

Task Flow

In this exercise, you will perform the following tasks:

  1. Check if the productID HT-1000 is available.
  2. Get the Sales Order IDs to the product ID HT-1000.
  3. Find the respective customer for each order of the product ID HT-1000.

Prerequisites

You have access to the SAP Demo Gateway system ES5.

Outcome After This Exercise

You check whether all OData APIs required later can be called up and that technical data, for example, the Product ID HT-1000, is available.

What do you Learn Within This Exercise

You will get to know the OData APIs to be used later. You understand the OData model.

Exercise Options

To carry out this exercise, you can choose from the following options:

  1. Live Environment: Using the instructions provided below, you can perform the steps in your SAP BTP account.
  2. Platform Simulation: Follow the step-by-step instructions within the simulation.
  3. Side-by-side: Follow the step-by-step instructions within the simulation and perform the steps in your SAP BTP account simultaneously.
Note
We strongly recommend to perform the steps in the live environment.

Task 1: Check if the Product ID HT-1000 is Available

Steps

  1. Check if the productID HT-1000 is available.

    1. Choose the following link: Check for HT-1000

    2. If the product ID exists you will get a data record to this product ID.

    3. Check out the response.

Task 2: Get the Sales Order IDs to the Product ID HT-1000

Steps

  1. How many sales orders are there for the product HT-1000?

    1. Choose the following link: Count the SalesOrders

    2. As result:

  2. Find the Sales Order ID and Item Position for the product ID HT-1000.

    1. Choose the following link: Check SalesOderID and ItemPosition

    2. The OData navigation /ToHeader is used to find out the customerID. Therefore we need the SalesOrderID and ItemPosition for every dataset entry.

Task 3: Find the Respective Customer for Each Order of the Product ID HT-1000

Steps

  1. Find the CustomerIDs for all SalesorderIDs and ItemPositions.

    1. Choose the following link: Check the CustomerID

    2. You get a dataset with the CustomerID.

  2. Find the address data to one customer.

    1. Choose the following link: Check the communication data

    2. You will get the address data for notification for every customer.

Log in to track your progress & complete quizzes