SlideShare a Scribd company logo
1 of 35
Alok Chhabria & Kritika Goyal (SAP Labs)
July 20, 2018
ODATA V4
The new way to REST
for your applications
2
• What is ODATA?
• Improvements in ODATA V4 over ODATA V2 ?
• SAP UI5 ODATA V4 Model
• Hands-On
- Initial Setup
- Data Access and Client Server Communication
- Automatic Data Type detection
- Batch Groups
- CRUD Enablement
- ODATA Operations (If time permits)
• Q and A
AGENDA
What is ODATA?
4
WHAT is ODATA?
According to www.odata.org :
OData (Open Data Protocol) is an ISO/IEC approved, 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.
 Industry-standard protocol for creating and consuming data APIs
 Based on core protocols like HTTP and open standards like XML and JSON
 Enables provision of data services based on REST principles
 Initiated by Microsoft, adopted by SAP, IBM and others
 Data handling using URLs constructed with specific rules
 Defines data formats representing resources like collections, entities, properties
 Optimized for consuming data, also known as “ODBC of the web”
OData URL structure:
http://services.odata.org/Northwind/Northwind.svc/Customers?$top=3
Service Root URI Resource Path Query options
Introduction to ODATA
ODATA V4 TripPin Sample Service-
http://services.odata.org/V4/TripPinServiceRW
http://www.odata.org/odata-services/
TripPin provides a service that can manage people's trips.
Key Features :
• Person Entity People  Collection of
entity
• Friends is a Navigation Property
• Gender is Enum Property
• Loc is a Spatial Property
• Photo is a media entity
• Create Update Delete
• Batch
• Async Request
• And many more…
Data Model
ODATA V4 TripPin Sample Service
http://services.odata.org/V4/TripPinServiceRW
http://www.odata.org/odata-services/
Try it Out ! (use POSTMAN or chrome )
.
we only use the entity type Person of the TripPin service. The entities of type Person are collected in the entity set People. Each Person has a
key property UserName and the properties Age, FirstName, and LastName
Description URL
Request People
Entity
http://services.odata.org/TripPinRESTierService/People
Request Single Entity http://services.odata.org/TripPinRESTierService/People('russellwhyte')
Request Single
Property (Enum)
http://services.odata.org/TripPinRESTierService/People('russellwhyte')/Gender/$value
$filter http://services.odata.org/TripPinRESTierService/People?$filter=FirstName eq 'Scott’
Metadata http://services.odata.org/V4/TripPinService/$metadata
$orderBy http://services.odata.org/V4/TripPinService/People?$orderby=length(FirstName)
desc,UserName
ODATAV2 vs ODATAV4
What has improved in ODATA V4
Performance
 New JSON Format (data): ~ 10% to 60% payload size reduction for lists after compression
 No inline metadata
 Messages part of payload (compressible) – V2 only header (not compressible)
 Lazy loading of huge service models
 In ODATA V2 payload had to be retrieved in both XML and JSON. With V4 XML is optional.
Features
 Improved datatypes: New data types (esp. in date/time area, e.g. Duration), inheritance, collection
values
 $filter with lambda operators ”any” and “all” for conditions on navigation properties
People?$filter=Emails/any(a:endswith(a,'@example.com'))
 $expand with query options
People?$expand=Friends($filter=Emails/any(a:endswith(a,'@example.com')))
 … and many more
New JSON Format - Sample Payload V2 vs. V4
V2 Payload Northwind Order_Details
V4 Payload Northwind Order_Details
New Data Types
• Date
• Fiori: V2 only has DateTime;
workaround "ignore time" is
error prone
(time zones, accidental day shift)
• TimeOfDay, Duration
• Replacements for Edm.Time
which is a duration of max. 24
hours
Payload Example:
"DateValue": "2012-12-03"
"DateTimeOffsetValue": "2012-12-03T07:16:23Z“
Edm.Date Date without a time-zone offset
Edm.DateTimeOffset Date and time with a time-zone offset, no leap seconds
Edm.Duration Signed duration in days, hours, minutes, and (sub)seconds
Edm.TimeOfDay Clock time 00:00-23:59:59.999999999999
Payload Example:
"TimeOfDayValue": "07:59:59.999"
"DurationValue": "P12DT23H59M59.999999999999S"
• Geo types for geographic data, and corresponding $filter functions
• Ideal fit with HANA Spatial
Payload Example:
"GeographyPoint": {"type": "Point","coordinates":[142.1,64.1]}
Edm.GeographyPoint A point in a round-earth coordinate system
… …
New Data Types
UI5 ODATA Model
 The OData Model enables binding of control
properties and aggregations to data from a
remote server
 The complete dataset is stored on the server
and only the requested fields are transferred
to the client
 Currently supported versions:
sap.ui.model.odata.v2.ODataModel
sap.ui.model.odata.v4.ODataModel
(Limited Feature Scope)
UI5 Component
View
Controllers
Server-side
Model
DB data
Data Engine
ODATA Model in UI5
15
Difference in ODATA V4 and ODATA V2 Models
OData operations executed via binding: Model
does not support the method callFunction.
Simplification: Use an operation binding instead;
it is now much easier to bind operation execution
results to controls.
No CRUD methods on model: Model does not
support the
methods create, read, remove, update.
Simplification: read, update, create and remove o
perations are available implicitly via the bindings,
so that changes are bound to controls.
Minimize APIs required for batch control: Model
does not support the
methodsgetChangeBatchGroups, getChangeGro
ups, getDeferredGroups,setChangeBatchGroups,
setChangeGroups, setDeferredBatchGroups,set
DeferredGroups, setUseBatch (and
corresponding model construction parameters).
Simplification: Batch groups are solely defined via
binding parameters with the corresponding
parameters on the model as default. You just
need the submitBatchmethod on the model to
control execution of the batch.
Hands-On
Setup Development Environment
• Setup SAP Cloud Platform HANA Trial Account
(https://account.hanatrial.ondemand.com/)
• After logging in, activate Neo trial.
• Go to Connectivity -> Destinations
• Create a destination with the following configuration:
• Go to Services -> Search WebIDE -> Launch WebIDE
Step 1: The Initial App
https://openui5.hana.ondemand.com/#/topic/15d84f36c0594cb2b3295aa1f55c
b961
• Follow the steps mentioned in the tutorial given on the link
• After clicking on the above hyperlink, click on the show source code button as shown below:
• Click on Download button and follow the further steps
Step 1: The Initial App
Continued..
• Import the downloaded project
• Run the project using index.html
• Currently the project runs with Mockdata
• Go to index.html and comment the following line of code:
• This causes your requests to go to actual northwind service
• Run the app- You will see data is not loaded.
Step 1: The Initial App
Continued..
• Right click on your project. Go to NEW -> HTML5 Application Descriptor
• You have a neo-app.json file added to your project
• Add the destination configuration code to your neo-app file.
• In your manifest file change your service URI to relative URI
Instead of hardcoded (To avoid CORS issue)
• Now the requests are routed to REAL backend service via the destination configured on SCP
• We will use real service for all exercises.
• If you face issues with the real service, feel free to switch to
• Mockserver by uncommenting the code in index.html
Step 2: Data Access and Client-Server Communication
https://openui5.hana.ondemand.com/#/topic/e9de002ddf1e478fbb9232bfba83d
cf0
• Add a refresh button and refresh the model if it doesn’t have any pending changes
• Study the calls in Chrome Developer Tools Console
• For more details, follow steps in link
Step 3: Automatic datatype detection
https://openui5.hana.ondemand.com/#/topic/96bb6e06fa22491fa65a5040f6da0
99c
• Add handleValidation: true to see UI validations based on metadata information
• You can start the mockserver, update local metadata and see the changes reflect in real time without
additional UI5 coding
• For detailed steps, follow the link given above
Auto-type detection
 Derive UI5 type from $metadata
Formatting, parsing, validation between model value and UI value
 Override by specifying type in binding information
Binding mode: TwoWay is default  Changes to model written to service backend
Step 4: Filtering, Sorting and Counting
https://openui5.hana.ondemand.com/#/topic/426ff318051a465191c861b51a74f
00e
• Here we add capabilities of Sort and Filter to our applications.
• Follow the steps in the tutorial
• The REAL TRIP PIN service does not support COUNT yet. To try out the COUNT functionality, switch to
Mockserver.
Step 5: Batch Groups
https://openui5.hana.ondemand.com/#/topic/ef2af4957fae469e9203e98006d3e
e75
• Batch Groups are used to group multiple requests into one to improve overall performance.
• Follow the steps in the tutorial
• Check the Batch Request in the Chrome developer tools Console and analyze the batch requests
Process Flow for Create Implementation
Attach Controller function for Create
Event in view
Call oBinding.create method to
create a new row with blank values
Refresh the model and set focus on
the newly created row
Step 6: Create and Edit
https://openui5.hana.ondemand.com/#/topic/b4f12660538147f8839b05cb03f1d
478
Step 6: Create and Edit
Continued…
Process Flow for UI Update Implementation
Attach OnInputChange event on all
Input fields (on liveChange property)
Set the UIChanges property as true if
the event is fired
If UserName has been changed, set
property UserNameEmpty to false
(for validation purposes)
Step 6: Create and Edit
Continued…
Process Flow for Save Implementation
Add SAVE button on footer, attach
event onPress
Define success and function
handlers for the ODATA request
Save the data to your backend by
calling SubmitBatch method with
appropriate batchGroupID
Step 6: Create and Edit
Continued…
Process Flow for Reset Implementation
Add RESET button on footer, attach
event onPress
Call method ResetChanges on the
items binding of the list
Step 6: Create and Edit
Continued…
Message Handling Process Flow
Initialize MessageManager and
MessageModel
AttachChange on MessageModel
ListBinding (Filter based on technical
Messages)
Get the technical messages and
display in MessageBox
Step 7: Delete
https://openui5.hana.ondemand.com/#/topic/12a0d1ef150a42ef81e9f07fe6407
018
Steps to follow for Delete Operation
Add DELETE button on the UI and
attach OnPress event
Get Binding Context for the selected
item and call delete function of the
context
Attach Success and Error handlers
We send parameter “$AUTO” for the delete call to ensure immediate effect of the request
Ensure only one record can be
selected in your list
Step 7: OData Operations
https://openui5.hana.ondemand.com/#/topic/a3e7cb6f671b4b839f37eb5f88429
e41
Steps to follow:
Add RESTART button on the UI and attach
OnPress event
The ResetDataSource action of the TripPin
service will reset the changes made in the
model during the complete exercise
Execute the operation using execute() method,
attach relevant success and failure handlers
We use (…) syntax to make the binding DEFERRED. This way the action can be called only on explicitly calling execute() method
Call bindContext method of the model with the
relevant action name
QUIZ TIME
• How do we enable BATCH in ODATA V4 model?
• Tell one difference between ODATA V4 Model and ODATA V2 Model?
• Tell one distinct feature of ODATA V4 which wasn’t available in V2?
• How to enable deferred processing for data operations? (Syntax)
• Can we apply sort and filter together on a list using ODATA V4?
• And one more……
QUIZ TIME
Did you enjoy the session?
Please give us your valuable feedback!!
Keep RESTing the V4 way  ADIOS!
34
Any
Questions?
Ask us anything…
Thank you.
Contact information:
Alok Chhabria (alok.chhabria@sap.com)
Kritika Goyal (kritika.goyal@sap.com)

More Related Content

What's hot

End to-end sap fiori extensibility use case
End to-end sap fiori extensibility use caseEnd to-end sap fiori extensibility use case
End to-end sap fiori extensibility use case
dkr786
 
Oracle r12 eb tax sql queries for functional implementers for troubleshooting...
Oracle r12 eb tax sql queries for functional implementers for troubleshooting...Oracle r12 eb tax sql queries for functional implementers for troubleshooting...
Oracle r12 eb tax sql queries for functional implementers for troubleshooting...
flower705
 
Oracle Eam Implementation Steps For Oracle E Am Module
Oracle Eam   Implementation Steps For Oracle E Am ModuleOracle Eam   Implementation Steps For Oracle E Am Module
Oracle Eam Implementation Steps For Oracle E Am Module
applearn
 
IDOC , ALE ,EDI
IDOC , ALE ,EDIIDOC , ALE ,EDI
IDOC , ALE ,EDI
Amit Khari
 
Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5
prakash185645
 

What's hot (20)

Introduction to ABAP
Introduction to ABAPIntroduction to ABAP
Introduction to ABAP
 
Infolets and OTBI Deep link Actionable Reports - Configuration Work Book
Infolets and OTBI Deep link Actionable Reports - Configuration Work Book Infolets and OTBI Deep link Actionable Reports - Configuration Work Book
Infolets and OTBI Deep link Actionable Reports - Configuration Work Book
 
Business partner-2
Business  partner-2Business  partner-2
Business partner-2
 
End to-end sap fiori extensibility use case
End to-end sap fiori extensibility use caseEnd to-end sap fiori extensibility use case
End to-end sap fiori extensibility use case
 
3 functional setup manager
3   functional setup manager3   functional setup manager
3 functional setup manager
 
Sap fiori
Sap fioriSap fiori
Sap fiori
 
Inventory receiving processes for serial controlled items
Inventory receiving processes for serial controlled itemsInventory receiving processes for serial controlled items
Inventory receiving processes for serial controlled items
 
Oracle r12 eb tax sql queries for functional implementers for troubleshooting...
Oracle r12 eb tax sql queries for functional implementers for troubleshooting...Oracle r12 eb tax sql queries for functional implementers for troubleshooting...
Oracle r12 eb tax sql queries for functional implementers for troubleshooting...
 
Oracle Eam Implementation Steps For Oracle E Am Module
Oracle Eam   Implementation Steps For Oracle E Am ModuleOracle Eam   Implementation Steps For Oracle E Am Module
Oracle Eam Implementation Steps For Oracle E Am Module
 
Oracle Time and Labor (OTL) Setup for Project
Oracle Time and Labor (OTL) Setup for ProjectOracle Time and Labor (OTL) Setup for Project
Oracle Time and Labor (OTL) Setup for Project
 
Oracle Applications R12 architecture
Oracle Applications R12 architectureOracle Applications R12 architecture
Oracle Applications R12 architecture
 
R12:Payment Process Request (PPR)
R12:Payment Process Request (PPR)R12:Payment Process Request (PPR)
R12:Payment Process Request (PPR)
 
How to create payslip through self service
How to create payslip through self serviceHow to create payslip through self service
How to create payslip through self service
 
Discrete Job Closure Process
Discrete Job Closure ProcessDiscrete Job Closure Process
Discrete Job Closure Process
 
Oracle EBS R12 Payroll user manual
Oracle EBS R12 Payroll user manualOracle EBS R12 Payroll user manual
Oracle EBS R12 Payroll user manual
 
IDOC , ALE ,EDI
IDOC , ALE ,EDIIDOC , ALE ,EDI
IDOC , ALE ,EDI
 
SAP S/4HANA Cloud
SAP S/4HANA CloudSAP S/4HANA Cloud
SAP S/4HANA Cloud
 
SAP PS Certification Overview (mindmap edition)
SAP PS Certification Overview (mindmap edition)SAP PS Certification Overview (mindmap edition)
SAP PS Certification Overview (mindmap edition)
 
Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5
 
Oracle apps-technical-tutorial
Oracle apps-technical-tutorialOracle apps-technical-tutorial
Oracle apps-technical-tutorial
 

Similar to Odata V4 : The New way to REST for Your Applications

Similar to Odata V4 : The New way to REST for Your Applications (20)

Using Modern Browser APIs to Improve the Performance of Your Web Applications
Using Modern Browser APIs to Improve the Performance of Your Web ApplicationsUsing Modern Browser APIs to Improve the Performance of Your Web Applications
Using Modern Browser APIs to Improve the Performance of Your Web Applications
 
cloud case study with practical hands on
cloud case study with practical hands oncloud case study with practical hands on
cloud case study with practical hands on
 
What's New for Developers in SharePoint 2013
What's New for Developers in SharePoint 2013What's New for Developers in SharePoint 2013
What's New for Developers in SharePoint 2013
 
Scaling Your Architecture with Services and Events
Scaling Your Architecture with Services and EventsScaling Your Architecture with Services and Events
Scaling Your Architecture with Services and Events
 
#SPSOttawa introduction to the #microsoftGraph
#SPSOttawa introduction to the #microsoftGraph#SPSOttawa introduction to the #microsoftGraph
#SPSOttawa introduction to the #microsoftGraph
 
Azure Application insights - An Introduction
Azure Application insights - An IntroductionAzure Application insights - An Introduction
Azure Application insights - An Introduction
 
POST/CON 2019 Workshop: Fundamentals
POST/CON 2019 Workshop: FundamentalsPOST/CON 2019 Workshop: Fundamentals
POST/CON 2019 Workshop: Fundamentals
 
Introduction to AWS X-Ray
Introduction to AWS X-RayIntroduction to AWS X-Ray
Introduction to AWS X-Ray
 
Config Management and Data Service Deep Dive
Config Management and Data Service Deep DiveConfig Management and Data Service Deep Dive
Config Management and Data Service Deep Dive
 
When Data Visualizations and Data Imports Just Don’t Work
When Data Visualizations and Data Imports Just Don’t WorkWhen Data Visualizations and Data Imports Just Don’t Work
When Data Visualizations and Data Imports Just Don’t Work
 
#Techorama belgium 2018 vincent biret what's new with the #MicrosoftGraph
#Techorama belgium 2018 vincent biret what's new with the #MicrosoftGraph#Techorama belgium 2018 vincent biret what's new with the #MicrosoftGraph
#Techorama belgium 2018 vincent biret what's new with the #MicrosoftGraph
 
MongoDB.local Austin 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...
MongoDB.local Austin 2018:  Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...MongoDB.local Austin 2018:  Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...
MongoDB.local Austin 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...
 
Presenting Data – An Alternative to the View Control
Presenting Data – An Alternative to the View ControlPresenting Data – An Alternative to the View Control
Presenting Data – An Alternative to the View Control
 
Monitoring modern applications: Introduction to AWS xray
Monitoring modern applications: Introduction to AWS xrayMonitoring modern applications: Introduction to AWS xray
Monitoring modern applications: Introduction to AWS xray
 
Salesforce awesome app buildout
Salesforce awesome app buildoutSalesforce awesome app buildout
Salesforce awesome app buildout
 
Tech Talk on Cloud Computing
Tech Talk on Cloud ComputingTech Talk on Cloud Computing
Tech Talk on Cloud Computing
 
Effective Microservices In a Data-centric World
Effective Microservices In a Data-centric WorldEffective Microservices In a Data-centric World
Effective Microservices In a Data-centric World
 
Tuli eServices_Mobile portfolio
 Tuli eServices_Mobile portfolio Tuli eServices_Mobile portfolio
Tuli eServices_Mobile portfolio
 
Shifan_QA_Resume
Shifan_QA_ResumeShifan_QA_Resume
Shifan_QA_Resume
 
SharePoint Custom Development
SharePoint Custom DevelopmentSharePoint Custom Development
SharePoint Custom Development
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Odata V4 : The New way to REST for Your Applications

  • 1. Alok Chhabria & Kritika Goyal (SAP Labs) July 20, 2018 ODATA V4 The new way to REST for your applications
  • 2. 2 • What is ODATA? • Improvements in ODATA V4 over ODATA V2 ? • SAP UI5 ODATA V4 Model • Hands-On - Initial Setup - Data Access and Client Server Communication - Automatic Data Type detection - Batch Groups - CRUD Enablement - ODATA Operations (If time permits) • Q and A AGENDA
  • 4. 4 WHAT is ODATA? According to www.odata.org : OData (Open Data Protocol) is an ISO/IEC approved, 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.
  • 5.  Industry-standard protocol for creating and consuming data APIs  Based on core protocols like HTTP and open standards like XML and JSON  Enables provision of data services based on REST principles  Initiated by Microsoft, adopted by SAP, IBM and others  Data handling using URLs constructed with specific rules  Defines data formats representing resources like collections, entities, properties  Optimized for consuming data, also known as “ODBC of the web” OData URL structure: http://services.odata.org/Northwind/Northwind.svc/Customers?$top=3 Service Root URI Resource Path Query options Introduction to ODATA
  • 6. ODATA V4 TripPin Sample Service- http://services.odata.org/V4/TripPinServiceRW http://www.odata.org/odata-services/ TripPin provides a service that can manage people's trips. Key Features : • Person Entity People  Collection of entity • Friends is a Navigation Property • Gender is Enum Property • Loc is a Spatial Property • Photo is a media entity • Create Update Delete • Batch • Async Request • And many more… Data Model
  • 7. ODATA V4 TripPin Sample Service http://services.odata.org/V4/TripPinServiceRW http://www.odata.org/odata-services/ Try it Out ! (use POSTMAN or chrome ) . we only use the entity type Person of the TripPin service. The entities of type Person are collected in the entity set People. Each Person has a key property UserName and the properties Age, FirstName, and LastName Description URL Request People Entity http://services.odata.org/TripPinRESTierService/People Request Single Entity http://services.odata.org/TripPinRESTierService/People('russellwhyte') Request Single Property (Enum) http://services.odata.org/TripPinRESTierService/People('russellwhyte')/Gender/$value $filter http://services.odata.org/TripPinRESTierService/People?$filter=FirstName eq 'Scott’ Metadata http://services.odata.org/V4/TripPinService/$metadata $orderBy http://services.odata.org/V4/TripPinService/People?$orderby=length(FirstName) desc,UserName
  • 9. What has improved in ODATA V4 Performance  New JSON Format (data): ~ 10% to 60% payload size reduction for lists after compression  No inline metadata  Messages part of payload (compressible) – V2 only header (not compressible)  Lazy loading of huge service models  In ODATA V2 payload had to be retrieved in both XML and JSON. With V4 XML is optional. Features  Improved datatypes: New data types (esp. in date/time area, e.g. Duration), inheritance, collection values  $filter with lambda operators ”any” and “all” for conditions on navigation properties People?$filter=Emails/any(a:endswith(a,'@example.com'))  $expand with query options People?$expand=Friends($filter=Emails/any(a:endswith(a,'@example.com')))  … and many more
  • 10. New JSON Format - Sample Payload V2 vs. V4 V2 Payload Northwind Order_Details V4 Payload Northwind Order_Details
  • 11. New Data Types • Date • Fiori: V2 only has DateTime; workaround "ignore time" is error prone (time zones, accidental day shift) • TimeOfDay, Duration • Replacements for Edm.Time which is a duration of max. 24 hours Payload Example: "DateValue": "2012-12-03" "DateTimeOffsetValue": "2012-12-03T07:16:23Z“ Edm.Date Date without a time-zone offset Edm.DateTimeOffset Date and time with a time-zone offset, no leap seconds Edm.Duration Signed duration in days, hours, minutes, and (sub)seconds Edm.TimeOfDay Clock time 00:00-23:59:59.999999999999 Payload Example: "TimeOfDayValue": "07:59:59.999" "DurationValue": "P12DT23H59M59.999999999999S"
  • 12. • Geo types for geographic data, and corresponding $filter functions • Ideal fit with HANA Spatial Payload Example: "GeographyPoint": {"type": "Point","coordinates":[142.1,64.1]} Edm.GeographyPoint A point in a round-earth coordinate system … … New Data Types
  • 14.  The OData Model enables binding of control properties and aggregations to data from a remote server  The complete dataset is stored on the server and only the requested fields are transferred to the client  Currently supported versions: sap.ui.model.odata.v2.ODataModel sap.ui.model.odata.v4.ODataModel (Limited Feature Scope) UI5 Component View Controllers Server-side Model DB data Data Engine ODATA Model in UI5
  • 15. 15 Difference in ODATA V4 and ODATA V2 Models OData operations executed via binding: Model does not support the method callFunction. Simplification: Use an operation binding instead; it is now much easier to bind operation execution results to controls. No CRUD methods on model: Model does not support the methods create, read, remove, update. Simplification: read, update, create and remove o perations are available implicitly via the bindings, so that changes are bound to controls. Minimize APIs required for batch control: Model does not support the methodsgetChangeBatchGroups, getChangeGro ups, getDeferredGroups,setChangeBatchGroups, setChangeGroups, setDeferredBatchGroups,set DeferredGroups, setUseBatch (and corresponding model construction parameters). Simplification: Batch groups are solely defined via binding parameters with the corresponding parameters on the model as default. You just need the submitBatchmethod on the model to control execution of the batch.
  • 17. Setup Development Environment • Setup SAP Cloud Platform HANA Trial Account (https://account.hanatrial.ondemand.com/) • After logging in, activate Neo trial. • Go to Connectivity -> Destinations • Create a destination with the following configuration: • Go to Services -> Search WebIDE -> Launch WebIDE
  • 18. Step 1: The Initial App https://openui5.hana.ondemand.com/#/topic/15d84f36c0594cb2b3295aa1f55c b961 • Follow the steps mentioned in the tutorial given on the link • After clicking on the above hyperlink, click on the show source code button as shown below: • Click on Download button and follow the further steps
  • 19. Step 1: The Initial App Continued.. • Import the downloaded project • Run the project using index.html • Currently the project runs with Mockdata • Go to index.html and comment the following line of code: • This causes your requests to go to actual northwind service • Run the app- You will see data is not loaded.
  • 20. Step 1: The Initial App Continued.. • Right click on your project. Go to NEW -> HTML5 Application Descriptor • You have a neo-app.json file added to your project • Add the destination configuration code to your neo-app file. • In your manifest file change your service URI to relative URI Instead of hardcoded (To avoid CORS issue) • Now the requests are routed to REAL backend service via the destination configured on SCP • We will use real service for all exercises. • If you face issues with the real service, feel free to switch to • Mockserver by uncommenting the code in index.html
  • 21. Step 2: Data Access and Client-Server Communication https://openui5.hana.ondemand.com/#/topic/e9de002ddf1e478fbb9232bfba83d cf0 • Add a refresh button and refresh the model if it doesn’t have any pending changes • Study the calls in Chrome Developer Tools Console • For more details, follow steps in link
  • 22. Step 3: Automatic datatype detection https://openui5.hana.ondemand.com/#/topic/96bb6e06fa22491fa65a5040f6da0 99c • Add handleValidation: true to see UI validations based on metadata information • You can start the mockserver, update local metadata and see the changes reflect in real time without additional UI5 coding • For detailed steps, follow the link given above Auto-type detection  Derive UI5 type from $metadata Formatting, parsing, validation between model value and UI value  Override by specifying type in binding information Binding mode: TwoWay is default  Changes to model written to service backend
  • 23. Step 4: Filtering, Sorting and Counting https://openui5.hana.ondemand.com/#/topic/426ff318051a465191c861b51a74f 00e • Here we add capabilities of Sort and Filter to our applications. • Follow the steps in the tutorial • The REAL TRIP PIN service does not support COUNT yet. To try out the COUNT functionality, switch to Mockserver.
  • 24. Step 5: Batch Groups https://openui5.hana.ondemand.com/#/topic/ef2af4957fae469e9203e98006d3e e75 • Batch Groups are used to group multiple requests into one to improve overall performance. • Follow the steps in the tutorial • Check the Batch Request in the Chrome developer tools Console and analyze the batch requests
  • 25. Process Flow for Create Implementation Attach Controller function for Create Event in view Call oBinding.create method to create a new row with blank values Refresh the model and set focus on the newly created row Step 6: Create and Edit https://openui5.hana.ondemand.com/#/topic/b4f12660538147f8839b05cb03f1d 478
  • 26. Step 6: Create and Edit Continued… Process Flow for UI Update Implementation Attach OnInputChange event on all Input fields (on liveChange property) Set the UIChanges property as true if the event is fired If UserName has been changed, set property UserNameEmpty to false (for validation purposes)
  • 27. Step 6: Create and Edit Continued… Process Flow for Save Implementation Add SAVE button on footer, attach event onPress Define success and function handlers for the ODATA request Save the data to your backend by calling SubmitBatch method with appropriate batchGroupID
  • 28. Step 6: Create and Edit Continued… Process Flow for Reset Implementation Add RESET button on footer, attach event onPress Call method ResetChanges on the items binding of the list
  • 29. Step 6: Create and Edit Continued… Message Handling Process Flow Initialize MessageManager and MessageModel AttachChange on MessageModel ListBinding (Filter based on technical Messages) Get the technical messages and display in MessageBox
  • 30. Step 7: Delete https://openui5.hana.ondemand.com/#/topic/12a0d1ef150a42ef81e9f07fe6407 018 Steps to follow for Delete Operation Add DELETE button on the UI and attach OnPress event Get Binding Context for the selected item and call delete function of the context Attach Success and Error handlers We send parameter “$AUTO” for the delete call to ensure immediate effect of the request Ensure only one record can be selected in your list
  • 31. Step 7: OData Operations https://openui5.hana.ondemand.com/#/topic/a3e7cb6f671b4b839f37eb5f88429 e41 Steps to follow: Add RESTART button on the UI and attach OnPress event The ResetDataSource action of the TripPin service will reset the changes made in the model during the complete exercise Execute the operation using execute() method, attach relevant success and failure handlers We use (…) syntax to make the binding DEFERRED. This way the action can be called only on explicitly calling execute() method Call bindContext method of the model with the relevant action name
  • 32. QUIZ TIME • How do we enable BATCH in ODATA V4 model? • Tell one difference between ODATA V4 Model and ODATA V2 Model? • Tell one distinct feature of ODATA V4 which wasn’t available in V2? • How to enable deferred processing for data operations? (Syntax) • Can we apply sort and filter together on a list using ODATA V4? • And one more……
  • 33. QUIZ TIME Did you enjoy the session? Please give us your valuable feedback!! Keep RESTing the V4 way  ADIOS!
  • 35. Thank you. Contact information: Alok Chhabria (alok.chhabria@sap.com) Kritika Goyal (kritika.goyal@sap.com)