Introduction to Odata
Open
Data Protocol -OData
:: Microsoft
has given us a way to access data as queryable and inter-operable using Restful
API under Microsoft Open Specification Promise.
It
is built upon WEB API Architecture by following REST. More of, it allows user
to make quarable service point. We can say re-usability features we use rather
than creating separate service points..
REST-Rules
Each resource should be identified by a URI
(unique identifier).
It uses HTTP protocol with API verbose GET, POST, PUT ,PATCH and DELETE method to
perform actions.
Representation of entity is exchanged on
server using verbose to perform action.
Application may have state but client session
data can’t be stored on the server.
Response can be cached at client side
Query
Options
$filter
?$filter=FirstName
eq 'rupesh'
$orderby
?$orderby=DateCreated
desc
Default-
Ordered in ascending order
desc-Descending
order
asc
-Ascending order
$top
and $skip
?$top=2
- Selecting the top N records
?$skip=10-
Skipping first N records and fetch next records
$count
/$count
- Records counts
$expand
include
related resource - load them all
$select
?$select=FirstName,
Email- Selected the columns values
$search
?$search=abc-
Searched in collection and returns only matched results
Lambda
Operators
?$filter=FirstName/any(s:endswith(s,
'khanna'))
OData defines two operators any and all
Any
- It checks whether at least one element in a collection satisfy a specified
condition if any matches returns true else false.
All-
Returns true if all the elements satisfy the condition else returns false.
Functions and Actions
OData
supports custom operations (Actions and Functions).
Functions
-No observable side effects.
Actions-
Observable side effects.
Few frequently used queries
with meaning
Add Addition ?$filter=price
add 5 lt 25
Sub Subtraction ?$filter=marks
sub 5 gt 80
Mul Multiplication ?$filter=stdcount
mul 2 gt 25
Div Division ?$filter=avgage
div 2 gt 60
Mod Modulo ?$filter=numberInt
mod 2 eq 0
Eq Equal ?$filter=FirstName
eq 'Raj'
Ne Not equal ?$filter=FirstName ne 'Raj'
Gt Greater than ?$filter=age gt 20
Ge Greater than or equal ?$filter=age ge 20
Lt Less than ?$filter=age
lt 20
Le Less than or equal ?$filter=age le 50
And Logical and ?$filter=age
le 50 and age gt 20
Or Logical or ?$filter=age le 20 or age gt 12
Not Logical negation ?$filter=not
endswith(email,'.com')
We will cover all the operation in details in next modules
Reference
Odata standard documents
Microsoft Odata
Introduction to Odata
Reviewed by Rupesh
on
08:35
Rating:
No comments: