Odata Introduction
By Ahmad Dwedar
Andalusia Group
For Medical Services
ADS Department
 What is Odata ?
 Features of Odata
 OData Server Platforms
 Querying in Odata
 OData Operators
 Logical Operators
 Arithmetic Operators
 Odata Functions
 String Functions
 Date Functions
 Math Functions
 Odata Practical Example
Agenda
Andalusia Group
For Medical Services
ADS Department
 Open Data Protocol (OData) is an open protocol which allows
the creation and consumption of query able and interoperable
Restful APIs in a simple and standard way. Microsoft initiated
OData in 2007.
 The protocol enables the creation and consumption of REST
APIs, which allow Web clients to publish and edit resources,
identified using URLs and defined in a data model, using simple
HTTP messages. OData is not limited to relational databases.
What is Odata ?
Andalusia Group
For Medical Services
ADS Department
 Odata supports most of the Http verbs: Get, Post, Put, Delete,
Patch, Merge
 It supports three types of data formatting: Xml, Json, and Json
light
 It is platform and language independent
 No need to create proxy classes which we used to do it in web
service. We don't need to serialize the output data manually,
OData does the serialization for us
 open source, simple, flexible and light-weight
Features of Odata
Andalusia Group
For Medical Services
ADS Department
 WCF Data Services
 ASP.NET Web API
 Share Point
 MS SQL Server Reporting Services
 Windows Azure
 PHP, Java, IBM WebSphere/DB2/Informix
 For the entire list visit http://www.odata.org/ecosystem/
OData Server Platforms
Andalusia Group
For Medical Services
ADS Department
Querying in Odata
Option Example
$FILTER http://HMS:80/Api/EmployeesApi?$Filter=id eq 10
$SELECT http://HMS:80/Api/EmployeesApi?$Select=id,name,salary
$TOP http://HMS:80/Api/EmployeesApi?$Top=10
$SKIP http://HMS:80/Api/EmployeesApi?$Skip=5
$ORDERBY http://HMS:80/Api/EmployeesApi?$OrderBy=name desc
$INLINECOUNT http://HMS:80/Api/EmployeesApi?$Inlinecount
Andalusia Group
For Medical Services
ADS Department
Operator Explanation Example
AND And Operation http://HMS:80/Api/EmployeesApi?$Filter=Age gt 25 and IsActive eq true
OR Or Operation http://HMS:80/Api/EmployeesApi?$Filter=JobID eq 5 or JobID eq 8
NOT Not Operation http://HMS:80/Api/EmployeesApi?$Filter=not endswith(name,‘dwedar')
EQ Equal Check http://HMS:80/Api/EmployeesApi?$Filter=Salary eq 1000
NE Not Equal Check http://HMS:80/Api/EmployeesApi?$Filter=JobID ne 2
LT Less Than Check http://HMS:80/Api/EmployeesApi?$Filter=Salary lt 3000
GT Greater Than Check http://HMS:80/Api/EmployeesApi?$Filter=Salary gt 3000
LE Less Than Equal http://HMS:80/Api/EmployeesApi?$Filter=Age le 30
GE Greater Than Equal http://HMS:80/Api/EmployeesApi?$Filter=Age ge 21
OData Operators
Andalusia Group
For Medical Services
ADS Department
Logical Operators
Operator Explanation Example
Add Addition http://HMS:80/Api/Products?$filter=Price add 5 gt 10
Sub Subtraction http://HMS:80/Api/Products?$filter=Price sub 5 gt 10
Mul Multiplication http://HMS:80/Api/Products?$filter=Price mul 2 gt 2000
Div Division http://HMS:80/Api/Products?$filter=Price div 2 gt 4
Mod Modulo http://HMS:80/Api/Products?$filter=Price mod 2 eq 0
Grouping Precedence grouping http://HMS:80/Api/Products?$filter=(Price sub 5) gt 10
OData Operators
Andalusia Group
For Medical Services
ADS Department
Arithmetic Operators
Function Signature Example
substringof (string, string field) $filter=substringof('ahmad', Name) eq true
Endswith/Startswith (string field, string) $filter=endswith(Name, ‘dwedar') eq true
trim (string) $filter=trim(CompanyName) eq 'Andalusia Inc'
length (string) $filter=length(CompanyName) eq 13
indexof (string field, string) $filter=indexof(CompanyName, 'Andalusia') eq 1
replace (string field, string find,
string replace)
$filter=replace(CompanyName, ' ', '') eq 'AndalusiaInc'
substring (string field, int pos) $filter=substring(CompanyName, 1) eq 'Andalusia Inc'
substring (string field, int pos, int
length)
$filter=substring(CompanyName, 1, 2) eq ‘An'
Tolower/Toupper (string field) $filter=tolower(CompanyName) eq ‘andalusia'
concat (string field, string) $filter=concat(concat(City, ', '), Country) eq 'Berlin, Germany'
Odata Functions
Andalusia Group
For Medical Services
ADS Department
String Functions
Function Signature Example
day (DateTime field) $filter=day(BirthDate) eq 8
hour (DateTime field) $filter=hour(BirthDate) eq 0
minute (DateTime field) $filter=minute(BirthDate) eq 0
month (DateTime field) $filter=month(BirthDate) eq 12
second (DateTime field) $filter=second(BirthDate) eq 0
year (DateTime field) $filter=year(BirthDate) eq 1980
Odata Functions
Andalusia Group
For Medical Services
ADS Department
Date Functions
Function Signature Example
round (double/decimal Field) $filter=round(Price) eq 6
floor (double/decimal Field) $filter=floor(Price) eq 8
ceiling (double/decimal Field) $filter=ceiling(Price) eq 13
Odata Functions
Andalusia Group
For Medical Services
ADS Department
Math Functions
Odata
Andalusia Group
For Medical Services
ADS Department
Odata Practical
Example
References
Andalusia Group
For Medical Services
ADS Department
 http://www.odata.org/documentation/odata-version-
3-0/url-conventions/
 http://www.odata.org/documentation/odata-version-
3-0/odata-version-3-0-core-protocol/
 http://www.odata.org/documentation/odata-version-
2-0/uri-conventions/
 https://en.wikipedia.org/wiki/Open_Data_Protocol

Odata introduction

  • 1.
    Odata Introduction By AhmadDwedar Andalusia Group For Medical Services ADS Department
  • 2.
     What isOdata ?  Features of Odata  OData Server Platforms  Querying in Odata  OData Operators  Logical Operators  Arithmetic Operators  Odata Functions  String Functions  Date Functions  Math Functions  Odata Practical Example Agenda Andalusia Group For Medical Services ADS Department
  • 3.
     Open DataProtocol (OData) is an open protocol which allows the creation and consumption of query able and interoperable Restful APIs in a simple and standard way. Microsoft initiated OData in 2007.  The protocol enables the creation and consumption of REST APIs, which allow Web clients to publish and edit resources, identified using URLs and defined in a data model, using simple HTTP messages. OData is not limited to relational databases. What is Odata ? Andalusia Group For Medical Services ADS Department
  • 4.
     Odata supportsmost of the Http verbs: Get, Post, Put, Delete, Patch, Merge  It supports three types of data formatting: Xml, Json, and Json light  It is platform and language independent  No need to create proxy classes which we used to do it in web service. We don't need to serialize the output data manually, OData does the serialization for us  open source, simple, flexible and light-weight Features of Odata Andalusia Group For Medical Services ADS Department
  • 5.
     WCF DataServices  ASP.NET Web API  Share Point  MS SQL Server Reporting Services  Windows Azure  PHP, Java, IBM WebSphere/DB2/Informix  For the entire list visit http://www.odata.org/ecosystem/ OData Server Platforms Andalusia Group For Medical Services ADS Department
  • 6.
    Querying in Odata OptionExample $FILTER http://HMS:80/Api/EmployeesApi?$Filter=id eq 10 $SELECT http://HMS:80/Api/EmployeesApi?$Select=id,name,salary $TOP http://HMS:80/Api/EmployeesApi?$Top=10 $SKIP http://HMS:80/Api/EmployeesApi?$Skip=5 $ORDERBY http://HMS:80/Api/EmployeesApi?$OrderBy=name desc $INLINECOUNT http://HMS:80/Api/EmployeesApi?$Inlinecount Andalusia Group For Medical Services ADS Department
  • 7.
    Operator Explanation Example ANDAnd Operation http://HMS:80/Api/EmployeesApi?$Filter=Age gt 25 and IsActive eq true OR Or Operation http://HMS:80/Api/EmployeesApi?$Filter=JobID eq 5 or JobID eq 8 NOT Not Operation http://HMS:80/Api/EmployeesApi?$Filter=not endswith(name,‘dwedar') EQ Equal Check http://HMS:80/Api/EmployeesApi?$Filter=Salary eq 1000 NE Not Equal Check http://HMS:80/Api/EmployeesApi?$Filter=JobID ne 2 LT Less Than Check http://HMS:80/Api/EmployeesApi?$Filter=Salary lt 3000 GT Greater Than Check http://HMS:80/Api/EmployeesApi?$Filter=Salary gt 3000 LE Less Than Equal http://HMS:80/Api/EmployeesApi?$Filter=Age le 30 GE Greater Than Equal http://HMS:80/Api/EmployeesApi?$Filter=Age ge 21 OData Operators Andalusia Group For Medical Services ADS Department Logical Operators
  • 8.
    Operator Explanation Example AddAddition http://HMS:80/Api/Products?$filter=Price add 5 gt 10 Sub Subtraction http://HMS:80/Api/Products?$filter=Price sub 5 gt 10 Mul Multiplication http://HMS:80/Api/Products?$filter=Price mul 2 gt 2000 Div Division http://HMS:80/Api/Products?$filter=Price div 2 gt 4 Mod Modulo http://HMS:80/Api/Products?$filter=Price mod 2 eq 0 Grouping Precedence grouping http://HMS:80/Api/Products?$filter=(Price sub 5) gt 10 OData Operators Andalusia Group For Medical Services ADS Department Arithmetic Operators
  • 9.
    Function Signature Example substringof(string, string field) $filter=substringof('ahmad', Name) eq true Endswith/Startswith (string field, string) $filter=endswith(Name, ‘dwedar') eq true trim (string) $filter=trim(CompanyName) eq 'Andalusia Inc' length (string) $filter=length(CompanyName) eq 13 indexof (string field, string) $filter=indexof(CompanyName, 'Andalusia') eq 1 replace (string field, string find, string replace) $filter=replace(CompanyName, ' ', '') eq 'AndalusiaInc' substring (string field, int pos) $filter=substring(CompanyName, 1) eq 'Andalusia Inc' substring (string field, int pos, int length) $filter=substring(CompanyName, 1, 2) eq ‘An' Tolower/Toupper (string field) $filter=tolower(CompanyName) eq ‘andalusia' concat (string field, string) $filter=concat(concat(City, ', '), Country) eq 'Berlin, Germany' Odata Functions Andalusia Group For Medical Services ADS Department String Functions
  • 10.
    Function Signature Example day(DateTime field) $filter=day(BirthDate) eq 8 hour (DateTime field) $filter=hour(BirthDate) eq 0 minute (DateTime field) $filter=minute(BirthDate) eq 0 month (DateTime field) $filter=month(BirthDate) eq 12 second (DateTime field) $filter=second(BirthDate) eq 0 year (DateTime field) $filter=year(BirthDate) eq 1980 Odata Functions Andalusia Group For Medical Services ADS Department Date Functions
  • 11.
    Function Signature Example round(double/decimal Field) $filter=round(Price) eq 6 floor (double/decimal Field) $filter=floor(Price) eq 8 ceiling (double/decimal Field) $filter=ceiling(Price) eq 13 Odata Functions Andalusia Group For Medical Services ADS Department Math Functions
  • 12.
    Odata Andalusia Group For MedicalServices ADS Department Odata Practical Example
  • 13.
    References Andalusia Group For MedicalServices ADS Department  http://www.odata.org/documentation/odata-version- 3-0/url-conventions/  http://www.odata.org/documentation/odata-version- 3-0/odata-version-3-0-core-protocol/  http://www.odata.org/documentation/odata-version- 2-0/uri-conventions/  https://en.wikipedia.org/wiki/Open_Data_Protocol