OData

The Best way to Rest

- Ritesh Ranjan

Agenda

  • What is OData

  • Why we need OData

  • Overview of OData Specs

Introduction

Open Data Protocol

 

  • OData is a protocol for the creation and consumption of RESTful APIs
  • Microsoft initiated OData in 2007
  • Version 4 is standardized with OASIS  (2014)

Why we need OData ?

Pre Rest Era !

SOAP

CORBA

The XML used to make requests and receive responses in SOAP can become extremely complex

Common Object Request Broker Architecture

Rest API

  • Architectural style that Roy T. Fielding deduced from the Web
  • Uses exiting HTTP Verbs - POST, GET, PUT, DELETE etc.
  • A url (Noun) is exposed a resource endpoint

www.oxford-university.com/students

If REST Works,

 Why to shake the

boat ??

Example

- API to get list of students

           www.oxford-university.com/students

           {

              "name" : "Jhon",

              "deparmemet" : "Arts"

              ....

           }  

- Now we need a way to order students by "name" and   filter by "department"

- We can create a new API or introduce new parameters

- Same thinking process of creating a way to query this API we will have to think again for other APIs

Tradition Rest Approach

  • With traditional REST approach generic programming would be difficult.
  • We would have to read the documentation of API and know which queries are possible, then may be hard-code the url’s etc.
  • Clients developed on top this may have to repeat this for each API they will calling for different resources.

OData 

(Open Data Protocol)

An OASIS standard that defines the best practice for building and consuming RESTful APIs.

Overview of the Protocols

- Service Root

- Resource Path

- Query Option

 

Resource identification

Service root -  http://host/service/

- The service document - http://host/service  Lists entity sets, functions, and singletons

 

- The metadata document - http://host/service/$metadata

       Describes the types, sets, functions and actions understood by the OData service

 

- Dynamic resources : The URIs may be computed from the hypermedia information in the service document and metadata.

 

- Resource operation - Leverages the HTTP verbs, POST, GET, DELETE etc.

Querying Data

  • /Products(1)
  • /Products?$filter=name eq 'Milk'
  • /Products?$select=name
  • /Products?$order=name
  • /Products?$top=10&$skip=10
  • /Products?$expand=Prices

Data Modification

  • Create an Entity

    POST serviceRoot/People
  • Delete an Entity

​                                DELETE serviceRoot/People

                                Update an Entity

​                                PATCH serviceRoot/People

 

 

 

Functions and Actions

 

- Functions are operations exposed by an OData service that MUST return data and MUST have no observable side effects

- Actions are operations MAY have side effects when invoked.

- Functions and actions both MAY bound to an entity type, primitive type

 

  • GET serviceRoot/GetNearestAirport(lat = 33, lon = -118)
     

Other Supported Features

  • ETag
  • Singleton e.g /serviceRoot/Me
  • Derived Entity type

Who are using OData

  • Microsoft

  • SAP

  • IBM

DEMO

OData

By ritesh ranjan

OData

  • 78