Jovan Popovic Microsoft
Jovan Popovic
Program manager MDCS/SQL Server/Azure
Azure/SQL/ASP.NET/JQuery
PhD Electrical Engineering
http://petlja.rs/
Agenda
• REST
• Why OData?
• OData – details
• Demo
What is REST?
• Way of providing interoperability between computer systems on
the Internet
• Stateless access on resources by Uri
• CRUD operations via HTTP methods
• POST – Create resource
• GET – Read resource
• PUT – Update resource
• DELETE – Delete resource
Problem – Custom REST Endpoints
• Clients need many custom queries.
• How to serve custom requests?
• Using custom Url
• /Company/ByName/Acme
• /CompanyByRegion(‘Serbia’)
• Using custom parameters
• /Company?Name=Acme
• /Company?Region=Serbia
SQL language
• How Databases solve this problem?
• SQL Language
• SELECT <columns>
• WHERE <condition>
• ORDER BY <columns>
• OFFSET <skip>
• FETCH <top>
Idea: SQL on top of REST
• Adding query clauses as parameters
• $select=
• $filter=
• $orderby=
• $take=
• $skip=
• OData standardizes query clauses
• Two types of parameters
• OData reserved parameters beginning with $
• Reserved for future usage
• Custom app-specific parameters cannot start with $
• You can put any parameter
OData specification
• Microsoft initiated OData in 2007.
• Versions 1.0, 2.0, and 3.0 are released under the Microsoft Open
Specification Promise.
• Version 4.0 was standardized at OASIS, March 2014.
• Standardized as ISO/IEC 20802:1 and 20801:2
• OData contributors
• Citrix Systems, IBM, Microsoft, Progress Software, Red Hat, SAP.
OData queries
How to query data via OData REST API
Output formats
• OData specifies the output format
• JSON(default)
• XML
• Response may include metadata
• odata.metadata=minimal
• odata.metadata=full
• odata.metadata=none
• Metadata may be used by client to understand data types in response and
generate client code (if needed)
Resources
• OData has top-level resources
• http://services.odata.org/TripPinRESTierService/People
• http://services.odata.org/TripPinRESTierService/Airlines
• http://services.odata.org/TripPinRESTierService/Airports
• Fetching resources by id/key
• http://services.odata.org/TripPinRESTierService/Airports('KSFO’)
• http://services.odata.org/TripPinRESTierService/People('russellwhyte’)
Querying data with $filter
• Relational expressions
• eq, ne, gt, lt, le, ge
• Logical expression
• and, or, not
• Examples
• http://services.odata.org/TripPinRESTierService/People?$filter=FirstName eq
'Scott'
• http://services.odata.org/TripPinRESTierService/People?$filter=FirstName eq
'Scott' or FirstName eq 'Russell'
Ordering results with $orderby
• Use any column and include direction (asc or desc)
• Examples
• http://services.odata.org/TripPinRESTierService/People?$orderby=FirstName
• http://services.odata.org/TripPinRESTierService/People?$orderby=FirstName
desc
Pagination
• Pagination parameters $skip and $top
• Example
• http://services.odata.org/TripPinRESTierService/People?$skip=30&$top=10
Expansion
• Include related entities with $expand parameter
• Examples
• http://services.odata.org/TripPinRESTierService/People('keithpinckney')?$exp
and=Trips
• http://services.odata.org/TripPinRESTierService/People('russellwhyte')?$expa
nd=Trips($top=1)
• http://services.odata.org/TripPinRESTierService/People('russellwhyte')?$expa
nd=Trips($filter=Name eq 'Trip in US’)
Functions and Actions
• Non-resource oriented REST Endpoints
• Example
• http://services.odata.org/TripPinRESTierService/GetNearestAirport(lat = 33,
lon = -118)
OData ecosystem
Client tools and server API
OData libraries
Demo time
How to build applications using OData services?
JQuery DataTable
o.js
o('StockItems')
.select("StockItemName,UnitPrice,TaxRate,ColorName,Size,Brand")
.where("UnitPrice lt 20")
.orderBy("UnitPrice", "asc")
.skip(20)
.take(10)
.get(data => $(".product-item").view(data) );
References
• http://www.odata.org
• Intro
• Understand OData in 6-steps
• Libraries
• JavaScript Clients: olingo, o.js
• OData vs GraphQL vs ORDS
• OData Services in .NET(Code Project)

OData Services

  • 1.
  • 2.
    Jovan Popovic Program managerMDCS/SQL Server/Azure Azure/SQL/ASP.NET/JQuery PhD Electrical Engineering http://petlja.rs/
  • 3.
    Agenda • REST • WhyOData? • OData – details • Demo
  • 4.
    What is REST? •Way of providing interoperability between computer systems on the Internet • Stateless access on resources by Uri • CRUD operations via HTTP methods • POST – Create resource • GET – Read resource • PUT – Update resource • DELETE – Delete resource
  • 5.
    Problem – CustomREST Endpoints • Clients need many custom queries. • How to serve custom requests? • Using custom Url • /Company/ByName/Acme • /CompanyByRegion(‘Serbia’) • Using custom parameters • /Company?Name=Acme • /Company?Region=Serbia
  • 6.
    SQL language • HowDatabases solve this problem? • SQL Language • SELECT <columns> • WHERE <condition> • ORDER BY <columns> • OFFSET <skip> • FETCH <top>
  • 7.
    Idea: SQL ontop of REST • Adding query clauses as parameters • $select= • $filter= • $orderby= • $take= • $skip= • OData standardizes query clauses • Two types of parameters • OData reserved parameters beginning with $ • Reserved for future usage • Custom app-specific parameters cannot start with $ • You can put any parameter
  • 8.
    OData specification • Microsoftinitiated OData in 2007. • Versions 1.0, 2.0, and 3.0 are released under the Microsoft Open Specification Promise. • Version 4.0 was standardized at OASIS, March 2014. • Standardized as ISO/IEC 20802:1 and 20801:2 • OData contributors • Citrix Systems, IBM, Microsoft, Progress Software, Red Hat, SAP.
  • 9.
    OData queries How toquery data via OData REST API
  • 10.
    Output formats • ODataspecifies the output format • JSON(default) • XML • Response may include metadata • odata.metadata=minimal • odata.metadata=full • odata.metadata=none • Metadata may be used by client to understand data types in response and generate client code (if needed)
  • 11.
    Resources • OData hastop-level resources • http://services.odata.org/TripPinRESTierService/People • http://services.odata.org/TripPinRESTierService/Airlines • http://services.odata.org/TripPinRESTierService/Airports • Fetching resources by id/key • http://services.odata.org/TripPinRESTierService/Airports('KSFO’) • http://services.odata.org/TripPinRESTierService/People('russellwhyte’)
  • 12.
    Querying data with$filter • Relational expressions • eq, ne, gt, lt, le, ge • Logical expression • and, or, not • Examples • http://services.odata.org/TripPinRESTierService/People?$filter=FirstName eq 'Scott' • http://services.odata.org/TripPinRESTierService/People?$filter=FirstName eq 'Scott' or FirstName eq 'Russell'
  • 13.
    Ordering results with$orderby • Use any column and include direction (asc or desc) • Examples • http://services.odata.org/TripPinRESTierService/People?$orderby=FirstName • http://services.odata.org/TripPinRESTierService/People?$orderby=FirstName desc
  • 14.
    Pagination • Pagination parameters$skip and $top • Example • http://services.odata.org/TripPinRESTierService/People?$skip=30&$top=10
  • 15.
    Expansion • Include relatedentities with $expand parameter • Examples • http://services.odata.org/TripPinRESTierService/People('keithpinckney')?$exp and=Trips • http://services.odata.org/TripPinRESTierService/People('russellwhyte')?$expa nd=Trips($top=1) • http://services.odata.org/TripPinRESTierService/People('russellwhyte')?$expa nd=Trips($filter=Name eq 'Trip in US’)
  • 16.
    Functions and Actions •Non-resource oriented REST Endpoints • Example • http://services.odata.org/TripPinRESTierService/GetNearestAirport(lat = 33, lon = -118)
  • 17.
  • 18.
  • 19.
    Demo time How tobuild applications using OData services?
  • 20.
  • 21.
  • 22.
    References • http://www.odata.org • Intro •Understand OData in 6-steps • Libraries • JavaScript Clients: olingo, o.js • OData vs GraphQL vs ORDS • OData Services in .NET(Code Project)