OData (Open Data Protocol) is an OASIS standard that defines a set of best practices for building and consuming RESTful APIs. OData helps you focus on your business logic while building RESTful APIs without having to worry about the various approaches to define request and response headers, status codes, HTTP methods, URL conventions, media types, payload formats, query options, etc. OData also provides guidance for tracking changes, defining functions/actions for reusable procedures, and sending asynchronous/batch requests.
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.
2. 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
3. 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
4. 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
5. 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
6. 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
7. 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
8. 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
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
13. 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