Building RESTful Applications with OData
-
Upload
todd-anglin -
Category
Technology
-
view
112 -
download
2
description
Transcript of Building RESTful Applications with OData
![Page 1: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/1.jpg)
Building RESTful Applications Building RESTful Applications with the Open Data Protocolwith the Open Data ProtocolTodd AnglinTodd AnglinChief Evangelist, Telerik
Level: Intermediate
![Page 2: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/2.jpg)
IntroductionsIntroductions
Todd Anglin
Chief Evangelist, TelerikMicrosoft MVP
ASP InsiderPresident NHDNUG & O’Reilly Author
@toddanglin
TelerikWatch.com
![Page 3: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/3.jpg)
The PlanThe Plan
![Page 4: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/4.jpg)
What you should learn today:What you should learn today:
• What is REST/OData• Who created REST/OData• Why use REST/OData• When should you use REST/OData• Where can you find REST/OData
![Page 5: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/5.jpg)
How did we get here?
![Page 6: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/6.jpg)
“There is a vast amount of data available today and data is now being collected and stored at a rate never seen before. Much, if not most, of this data however is locked into specific applications or formats and difficult to access or to integrate into new uses.”
- OData.org
![Page 7: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/7.jpg)
State of Data & ServicesState of Data & Services
Internal SQL
Internal SQL
My App
AppDataAppData
CMSCMS
SharePointSharePoint
CloudCloud
Custom API
SQL
JSON ServicesFBFB
![Page 8: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/8.jpg)
What is REST?What is REST?
• Representational State Transfer
• What is the biggest REST implementation?– World Wide Web!
REST is NOT a standard!(But it uses standards)
HTTP + URLs + XML*
![Page 9: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/9.jpg)
REST PrinciplesREST Principles
![Page 10: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/10.jpg)
REST IllustratedREST Illustrated
Magic Kingdom(Resource)
http://disneyworld.com/parks/magic-kingdomResource URL
Representation
URL Click
(State Transfer)
Representation
![Page 11: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/11.jpg)
RESTful ServicesRESTful Services
• Core idea:
let's have computers use the web the way humans do
![Page 12: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/12.jpg)
Alternatives to RESTAlternatives to REST
• Most common: SOAP and RPC
• Why use SOAP (vs REST)?– Enterprise security features (WS-Security)
– ACID Transactions (WS-AtomicTransaction)
– Message error recovery (WS-ReliableMessaging)
SOAP services focus on exposing application logicREST services focus on exposing “data” (or CRUD operations on data)
SOAP services focus on exposing application logicREST services focus on exposing “data” (or CRUD operations on data)
![Page 13: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/13.jpg)
OData does for data what REST does for services
![Page 14: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/14.jpg)
(Finally!) What is OData?(Finally!) What is OData?
• HTTP– REST-based services
• AtomPub– Data structure
• JSON – Data delivery format
Data silo buster
![Page 15: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/15.jpg)
Why?Why?
• Interoperability– Predictable access to data from any system
• Gaining popularity– SharePoint 2010
– SQL Server 2008 R2
– IBM WebSphere eXtreme Scale
– Azure Table Storage
– Telerik TeamPulse
– …
![Page 16: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/16.jpg)
REST AND ODATA IN REST AND ODATA IN ACTIONACTION
DEMO
![Page 17: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/17.jpg)
Consuming ODataConsuming OData
• Windows Phone 7 / iPhone / Mobile• AJAX / Javascript • PHP / Java / .NET • Silverlight • PowerPivot • Simple HTTP Requests (GET, POST, PUT,
DELETE)• More…
![Page 18: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/18.jpg)
Visual Studio ToolsVisual Studio Tools
• Open Data Protocol Visualizer
![Page 19: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/19.jpg)
CONSUMING EXISTING CONSUMING EXISTING ODATAODATA
DEMO
![Page 20: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/20.jpg)
Creating OData ServiceCreating OData Service
• As simple as returning proper XML/JSON– No specific platform requirements
• Ways to build:– Using Visual Studio tools (WCF Data Services)
– SharePoint Lists
– Azure Table Storage
– Manually produce XML
![Page 21: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/21.jpg)
WCF Data Services (Astoria)WCF Data Services (Astoria)
• Build RESTful services on Microsoft platform– Roots of OData protocol
• Built on WCF– Supports ATOM (XML) and JSON data representations
• Automates REST for data– Anything that implements IQueryable<T> or IUpdatable<T>
– EX: EF, LinqToSQL, 3rd party ORM, etc.
![Page 22: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/22.jpg)
WCF DATA SERVICES WCF DATA SERVICES BASICSBASICS
DEMO
![Page 23: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/23.jpg)
Service OperationsService Operations
• Functions exposed by OData– Similar to RPC
– Accept zero or more primitive type input params
– Can return scalar value
– [WebGet] is used for an addressable query
– [WebInvoke] is used for insert, update, and delete
http://.../OData.svc/GetProductsByRating?rating=5
![Page 24: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/24.jpg)
InterceptorsInterceptors
• Query Interceptors– Logic runs when resource is requested
– Uses: limit the data viewed, log, perform security check
• Change Interceptors– Logic runs when a change (Add/Edit/Delete) request
is made (HTTP PUT/POST/DELETE)
![Page 25: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/25.jpg)
SERVICE OPS & SERVICE OPS & INTERCEPTORSINTERCEPTORS
DEMO
![Page 26: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/26.jpg)
Securing Data ServicesSecuring Data Services
• Remember!– REST is NOT a protocol, it’s a pattern
• Same security that applies to HTTP, AtomPub, JSON
• Other options:– EntitySetRights
– Hiding sensitive data with [IgnoreProperties]
– Infrastructure security – SSL, IP Filtering
– QueryInterceptors
![Page 27: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/27.jpg)
OData & SharePoint 2010OData & SharePoint 2010
• ListData.svc– Out-of-the-box OData access to SharePoint data
– Data is NOT anonymously available!
http://siteurl/_vti_bin/listdata.svc/Announcements
![Page 28: Building RESTful Applications with OData](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c6f4174a795967778b456b/html5/thumbnails/28.jpg)
When to REST?When to REST?
1. Stateless web services
2. Scalable web services (via HTTP caching)
3. Mutually understood context (OData)
4. Restricted bandwidth (Mobile)
Always, except when there is a reason NOT to REST