Introducing OData Services

After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Describe basic concepts of OData

Introducing OData Services

Open Data Protocol (OData) is an OASIS standard that defines the best practice for building and consuming RESTful APIs. OData helps you to focus on your business logic, while building RESTful APIs, without having to worry about the approaches to define request and response headers, status codes, HTTP methods, URL conventions, media types, payload formats, query options, and so on. It is an open standard, defined by the OASIS consortium.

OData also guides you in tracking changes, defining functions or actions for reusable procedures, sending asynchronous or batch requests, and so on. Additionally, OData provides a facility for extension to fulfill any custom needs of your RESTful APIs.

OData RESTful APIs are easy to consume. The OData metadata, a machine-readable description of the data model of the APIs, enables the creation of powerful generic client proxies and tools. Some of these can help you interact with OData, even without knowing anything about the protocol.

OData Basics

One of the main features of OData is that it uses the existing HTTP verbs GET, PUT, POST, and DELETE against addressable resources identified in the URI. Conceptually, OData is a way of performing database-style create, read, update, and delete operations on resources by using HTTP verbs:

  • GET: Get the resource (a collection of entities, a single entity, a structural property, and so on).
  • POST: Create a new resource.
  • PUT: Update an existing resource by replacing it with a complete instance.
  • PATCH: Update an existing resource by replacing part of its properties with a partial instance.
  • DELETE: Remove the resource.

Data is transferred over HTTP using the Atom or JSON format.

The main aim of OData is to define an abstract data model and a protocol, which, combined, enable any client to access data exposed by any data source. Clients might include web browsers, mobile devices, business-intelligence tools, and custom applications, for example, custom applications written in programming languages such as PHP or Java. Data sources can include databases, content-management systems, the Cloud, or custom applications, for example, custom applications written in Java.

The OData approach to data exchange involves the following elements:

  • OData data model

    Provides a generic way to organize and describe data. OData uses the Entity 1 Data Model (EDM).

  • OData protocol

    Enables a client to query an OData service. The OData protocol is a set of interactions, which includes the usual REST-based create, read, update, and delete operations, along with an OData-defined query language. The OData service sends data in either of the following ways:

    • XML-based format defined by Atom/AtomPub

    • JSON

  • OData client libraries

    Enable access to data via the OData protocol. Since most OData clients are applications, pre-built libraries for making OData requests and getting results reduces and simplifies work for the developers who create those applications.

    A broad selection of OData client libraries are already widely available, for example: Android, Java, JavaScript, PHP, Ruby, and the best known mobile platforms.

  • OData services

    Exposes an end point that allows access to data in the SAP HANA database.

    An OData service is a logical data model; it describes entities (resources) using associations and operations. The most important point is that the OData service forms a kind of contract between the UI and the back-end system side, helping to bring together developers on both sides.

    There are two types of document associated with each OData service:

    • the service document
    • the service metadata document

    The service document lists entity sets, 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 available at http://<host>:<port>/<service>/.

    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 service metadata document is available at http://<host>:<port>/<service>/$metadata. The URL will return XML metadata of the service (Entity data model). The response of a service metadata document only supports XML.

Log in to track your progress & complete quizzes