Your SlideShare is downloading. ×

Autodesk Technical Webinar: SAP NetWeaver Gateway Part 2

577
views

Published on

OData - An Introduction and Examples …

OData - An Introduction and Examples

Agenda:
Why We Need OData
A Basic Introduction to OData
Structure of an OData Service
OData Operations
OData Query Language

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
577
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
39
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. OData An Introduction and Examples
  • 2. Agenda Why We Need OData A Basic Introduction to OData Structure of an OData Service OData Operations OData Query Language © 2012 SAP AG. All rights reserved. 2
  • 3. SAP’s Aim One SAP Thousands (non) SAP developers One billion consumers Provides Add Need  Server infrastructures,  Scale application  Consumer–level user multiple platforms  SDKs & libraries  App. dev. frameworks development  Idea creators  Web style apps  Limited ABAP and SAP process knowhow experience  Enterprise quality  Data security  Task-centric  Web style & mobile apps  Business applications  Enterprise quality  Data security © 2012 SAP AG. All rights reserved. 3
  • 4. Market and Industry Trends Data Silos Web Documents © 2012 SAP AG. All rights reserved. Open Data Server Web APIs Isolated Data Isolated Services Services Linked Data and Services 4
  • 5. Agenda Why We Need OData A Basic Introduction to OData Structure of an OData Service OData Operations OData Query Language © 2012 SAP AG. All rights reserved. 6
  • 6. OData at a Glance URIs for resource identification Uniform operations, defined by HTTP • GET, POST, PUT, PATCH, DELETE always mean the same Well known data formats • AtomPub & JSON Query language  “ODBC for the Web” Schema information  Data model description Based on entity and relationship model Hypermedia design patterns © 2012 SAP AG. All rights reserved. 7
  • 7. Agenda Why We Need OData A Basic Introduction to OData Structure of an OData Service OData Operations OData Query Language © 2012 SAP AG. All rights reserved. 8
  • 8. First OData Example: The Service Document OData service root URI: http://services.odata.org/OData/OData.svc/ © 2012 SAP AG. All rights reserved. 9
  • 9. First OData Example: The Service Metadata Document OData service root URI: http://services.odata.org/OData/OData.svc/ OData service metadata URI := <OData service root URI> + “$metadata” http://services.odata.org/OData/OData.svc/$metadata © 2012 SAP AG. All rights reserved. 10
  • 10. The OData Meta Model Function Import Entity Container * * Entity Set * Association * Service Document * 2 Entity Key * Entity Type 1 Entity Describes structure of 1 1..* 1 Navigation Property * 1..* Property * 1 Type 1..* Complex Type © 2012 SAP AG. All rights reserved. Simple Type 11
  • 11. The OData Meta Model Function Import Entity Container * * Entity Set * Association * Service Document * 2 Entity Key * Entity Type 1 Entity Describes structure of 1 1..* 1 Navigation Property * 1..* Property * 1 Type 1..* Complex Type © 2012 SAP AG. All rights reserved. Simple Type 12
  • 12. The OData Meta Model Function Import Entity Container * * Entity Set * Association * Service Document * 2 Entity Key * Entity Type 1 Entity Describes structure of 1 1..* 1 Navigation Property * 1..* Property * 1 Type 1..* Complex Type © 2012 SAP AG. All rights reserved. Simple Type 13
  • 13. The OData type system Function Import Entity Container * * Entity Set * Association * Service Document * 2 Entity Key * Entity Type 1 Entity Describes structure of 1 1..* 1 Navigation Property * 1..* Property * 1 Type 1..* Complex Type © 2012 SAP AG. All rights reserved. Simple Type 14
  • 14. Agenda Why We Need OData A Basic Introduction to OData Structure of an OData Service OData Operations OData Query Language © 2012 SAP AG. All rights reserved. 15
  • 15. http://services.odata.org/OData/OData.svc/Products/?$top=3 © 2012 SAP AG. All rights reserved. 16
  • 16. http://services.odata.org/OData/OData.svc/Products(0) © 2012 SAP AG. All rights reserved. 17
  • 17. http://services.odata.org/OData/OData.svc/Products(0)/Category © 2012 SAP AG. All rights reserved. 18
  • 18. http://services.odata.org/OData/OData.svc/Products(0)/Supplier © 2012 SAP AG. All rights reserved. 19
  • 19. CRUD Operations Operation on resource HTTP verb Create POST Read Update Delete GET © 2012 SAP AG. All rights reserved. PUT DELETE 20
  • 20. CRUD Operations POST $batch(multiple requests) : multiple responses Function Import Entity Container * * * Association * * Entity Type 1 Entity 1..* Navigation Property 1..* Property * 1 Type 1..* Complex Type © 2012 SAP AG. All rights reserved. GET() : feed POST(entry) : entry Describes structure of 1 1 * Service Document * 2 Entity Key <ServiceRootURI>$batch Entity Set Simple Type GET() : entry PUT(etag, entry) : nil PATCH(etag, partial entry) : nil DELETE() : nil 21
  • 21. OData beyond CRUD operations Function Import Entity Container * * Entity Set http://services.odata.org/OData/OData.svc/GetProductsByRating?rating=4 * * Association * Service Document * 2 … Entity Key * Entity Type 1 Entity Describes structure of 1 1..* 1 Navigation Property 1..* Property * 1 Type 1..* Complex Type © 2012 SAP AG. All rights reserved. Simple Type 22
  • 22. http://services.odata.org/OData/OData.svc/GetProductsByRating?rating=4 © 2012 SAP AG. All rights reserved. 23
  • 23. Agenda Why We Need OData A Basic Introduction to OData Structure of an OData Service OData Operations OData Query Language © 2012 SAP AG. All rights reserved. 24
  • 24. “ODBC” for the Web - Simple Query Language List of (most important) Query options: Operation Query option Filtering $filter Projecting $select Sorting $orderby Paging $top and $skip Inlining $expand Reference: http://www.odata.org/developers/protocols/uri-conventions#QueryStringOptions © 2012 SAP AG. All rights reserved. 25
  • 25. “ODBC” for the Web - Simple Query Language Filtering  $filter http://services.odata.org/OData/OData.svc/Products/?$filter=Price le 20 • All products with a price that is less than or equal to 20. Projecting  $select http://services.odata.org/OData/OData.svc/Products?$select=Price,Name • In a response from an OData service, only the Price and Name Property values are returned for each Product Entry in the Collection of products identified. © 2012 SAP AG. All rights reserved. 26
  • 26. “ODBC” for the Web - Simple Query Language Sorting  $orderby http://services.odata.org/OData/OData.svc/Products?$orderby=Rating asc • All Product Entries returned in ascending order when sorted by the Rating Property. © 2012 SAP AG. All rights reserved. 27
  • 27. “ODBC” for the Web - Simple Query Language Paging  $top and $skip http://services.odata.org/OData/OData.svc/Products?$top=5 • The first 5 Product Entries are returned where the Set of Products is sorted using a scheme determined by the OData service. http://services.odata.org/OData/OData.svc/Products?$top=5&$orderby=Name desc • The first 5 Product Entries are returned in descending order when sorted by the Name property. http://services.odata.org/OData/OData.svc/Categories(1)/Products?$skip=2 • The set of Product Entries (associated with the Category Entry identified by key value 1) starting with the third product. © 2012 SAP AG. All rights reserved. 28
  • 28. Typical Programming Patterns for UI-Centric Applications
  • 29. $filter and $select Use cases: Get all business partners whose company name starts with the letter ‘S’. Get all sales orders with a total sum exceeding than 10,000 €. Business Partners (4) S* Name 0100 SAP 0141 South American IT Company 0142 Get the business partner ID and the name of a business partner only. ID Siwusha 0143 Sorali t © 2012 SAP AG. All rights reserved. 12345 u 01/04 30
  • 30. Query Options: $filter & $select Request: GET …/BusinessPartners?$filter=startswith(CompanyName,'S‘)&$select=BusinessPartnerID,CompanyName Result { "BusinessPartnerID": "0100000000", "CompanyName": "SAP„ }, SQL analogy: "BusinessPartnerID": "0100000041", "CompanyName": "South American IT Company“ }, SELECT BusinessPartnerID CompanyName FROM BusinessPartners WHERE CompanyName LIKE ‘S%‘ { { "BusinessPartnerID": "0100000042", "CompanyName": "Siwusha„ }, { "BusinessPartnerID": "0100000044", "CompanyName": "Sorali„ } © 2012 SAP AG. All rights reserved. 31
  • 31. Paged Results Use case: Business Partners (45) Tell the user that just 6 out of 45 entries are displayed. Show a list in a paged view. Get the first 5 entries of a list only. Avoid scrolling through long lists in mobile applications. Business Partners (45) Business Partners (45) ID Name ID Name ID Name 0100 SAP 0106 Asia High tech 0112 New Line Design 0101 Becker Berlin 0107 Laurent 0113 HEPA Tec 0102 DelBont Industries 0108 AVANTEL 0114 Telecomunicaciones Star 0103 Talpa 0109 Telecomunicaciones Star 0115 Anav Ideon 0104 Panorama Studios 0110 Pear Computing Services 0116 Mexican Oil Trading Company 0111 Alpine Systems 0117 Meliva 0105 TECUM t © 2012 SAP AG. All rights reserved. 12345 u 01/06 t 12345 u 07/12 t 12345 u 13/18 32
  • 32. Query Options: $top and $inlinecount /BusinessPartners? $top=6 & $inlinecount=allpages &$select=BusinessPartnerID,CompanyName & $skip=6 Business Partners (45) 0100 SAP Becker Berlin 0102 DelBont Industries 0103 Talpa 0104 Panorama Studios 0105 Only limited amount of data has to be transferred Name 0101 Client side paging: ID TECUM t © 2012 SAP AG. All rights reserved. 12345 u 01/06 33
  • 33. Query Options: $top and $inlinecount and $skip /BusinessPartners? $top=6 & $inlinecount=allpages & $select=BusinessPartnerID,CompanyName & $skip=6 Business Partners (45) Business Partners (45) ID Name ID Name 0100 SAP 0106 Asia High tech 0101 Becker Berlin 0107 Laurent 0102 DelBont Industries 0108 AVANTEL 0103 Talpa 0109 Telecomunicaciones Star 0104 Panorama Studios 0110 Pear Computing Services 0111 Alpine Systems 0105 TECUM t © 2012 SAP AG. All rights reserved. 12345 u 01/06 t 12345 u 07/12 34
  • 34. Query Options: $top and $inlinecount and $skip /BusinessPartners? $top=6 & $inlinecount=allpages & $select=BusinessPartnerID,CompanyName & $skip=12 Business Partners (45) Business Partners (45) Business Partners (45) ID Name ID Name ID Name 0100 SAP 0106 Asia High tech 0112 New Line Design 0101 Becker Berlin 0107 Laurent 0113 HEPA Tec 0102 DelBont Industries 0108 AVANTEL 0114 Telecomunicaciones Star 0103 Talpa 0109 Telecomunicaciones Star 0115 Anav Ideon 0104 Panorama Studios 0110 Pear Computing Services 0116 Mexican Oil Trading Company 0111 Alpine Systems 0117 Meliva 0105 TECUM t © 2012 SAP AG. All rights reserved. 12345 u 01/06 t 12345 u 07/12 t 12345 u 13/18 35
  • 35. Navigation Properties EDMX graphical model: Business Partner SAP Details ID 0100 Company Name SAP Email karl.mueller @sap.com Adress Dietmar Hopp Allee 16 Service metadata document 69190 Walldorf Phone Number +49 6227 … Sales Orders © 2012 SAP AG. All rights reserved. u 36
  • 36. Navigation Properties GET /BusinessPartners('0100000000')/SalesOrd ers results": [ { "Currency": "EUR", "Status": "N", "SalesOrderID": "0500000026", "TotalSum": "1137.64" }, Business Partner SAP Sales Orders Details Customer = SAP ID 0100 Company Name SAP Email karl.mueller @sap.com Adress { "Currency": "EUR", "Status": "N", "SalesOrderID": "0500000027", "TotalSum": "1137.64" }, ID Dietmar Hopp Allee 16 69190 Walldorf Phone Number Status 0526 1137.64 EUR l 0527 1137.64 EUR l 0509 3972.22 EUR l +49 6227 … Sales Orders { Sum u "Currency": "EUR", "Status": "N", "SalesOrderID": "0500000009", "TotalSum": "3972.22" } ] © 2012 SAP AG. All rights reserved. 37
  • 37. $expand BusinessPartner #1 Use cases for navigation properties Get all sales orders of a business partner Get all sales order items of a sales order Get all sales orders and all sales order items of a business partner SalesOrder #1 SalesOrderItem #1 SalesOrderItem #2 SalesOrderItem #n Example Without $expand – 2 calls • First call • Second call SalesOrder #n /BusinessPartners(1) /BusinessPartners(1)/SalesOrders SalesOrderItem #1 SalesOrderItem #2 With $expand – 1 call • SalesOrderItem #n /BusinessPartners(1)?$expand=SalesOrders BusinessPartner #2 © 2012 SAP AG. All rights reserved. SalesOrder #1 39
  • 38. Deep Insert Updates of hierarchical data SalesOrder Example: Create a sales order together with sales order items in just one request. SalesOrderItem #1 SalesOrderItem #2 SalesOrderItem #n © 2012 SAP AG. All rights reserved. 40
  • 39. Media Links Use cases Show product pictures Upload pictures taken with device camera © 2012 SAP AG. All rights reserved. 41
  • 40. Media Links Subtitle Example GET …/Products('HT-1040') <entry> <link href="Products('HT-1040')" rel="edit" title="Product"/> <link href="Products('HT-1040')/$value" rel="edit-media" type="image/jpeg"/> <content type="image/jpeg" src="/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/HT-1040.jpg"/> <m:properties> <d:ProductID>HT-1040</d:ProductID> <d:Category>Laser printers</d:Category> <d:Name>Laser Professional Eco</d:Name> <d:Description>…</d:Description> <d:ProductPicUrl>/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/HT-1040.jpg</d:ProductPicUrl> <d:ProductPicUrlMimeType>image/jpeg</d:ProductPicUrlMimeType> </m:properties> </entry> © 2012 SAP AG. All rights reserved. 42
  • 41. Related Information For more information about the topics discussed in this lesson, see:  http://www.odata.org  Open Data Protocol by Example (focusing on the Atom protocol)  http://blogs.msdn.com/b/lightswitch/archive/2012/03/22/lightswitcharchitecture-odata.aspx © 2012 SAP AG. All rights reserved. 43
  • 42. Thank You!