building restful applications with odata

29
Building RESTful Applications Building RESTful Applications with the Open Data Protocol with the Open Data Protocol Todd Anglin Todd Anglin Chief Evangelist, Telerik Level: Intermediate

Upload: todd-anglin

Post on 27-Jan-2015

115 views

Category:

Technology


2 download

DESCRIPTION

Applications today are expected to expose their data and consume data-centric services via REST. In this session we discuss what REST is and have an overview of WCF Data Services and see how we can REST enable your data using the Open Data Protocol (OData). Then you will learn how to leverage existing skills related to Visual Studio, LINQ and data access to customize the behavior, control-flow, security model and experience of your data service. We will then see how to enable data-binding to traditional ASP.NET controls as well as Silverlight and Excel PowerPivot. We’ll then turn to consuming SharePoint and other OData based applications in .NET as well as from a non-Microsoft client. This is a very demo intensive session.

TRANSCRIPT

Page 1: Building RESTful Applications with OData

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

IntroductionsIntroductions

Todd Anglin

Chief Evangelist, TelerikMicrosoft MVP

ASP InsiderPresident NHDNUG & O’Reilly Author

@toddanglin

TelerikWatch.com

Page 3: Building RESTful Applications with OData

The PlanThe Plan

Page 4: Building RESTful Applications with OData

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

How did we get here?

Page 6: Building RESTful Applications with OData

“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

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

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

REST PrinciplesREST Principles

Page 10: Building RESTful Applications with OData

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

RESTful ServicesRESTful Services

• Core idea:

let's have computers use the web the way humans do

Page 12: Building RESTful Applications with OData

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

OData does for data what REST does for services

Page 14: Building RESTful Applications with OData

(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

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

REST AND ODATA IN REST AND ODATA IN ACTIONACTION

DEMO

Page 17: Building RESTful Applications with OData

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

Visual Studio ToolsVisual Studio Tools

• Open Data Protocol Visualizer

Page 19: Building RESTful Applications with OData

CONSUMING EXISTING CONSUMING EXISTING ODATAODATA

DEMO

Page 20: Building RESTful Applications with OData

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

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

WCF DATA SERVICES WCF DATA SERVICES BASICSBASICS

DEMO

Page 23: Building RESTful Applications with OData

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

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

SERVICE OPS & SERVICE OPS & INTERCEPTORSINTERCEPTORS

DEMO

Page 26: Building RESTful Applications with OData

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

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

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

Page 29: Building RESTful Applications with OData

[Q & A][Q & A]Thanks! Gracias! Mersi! Blagodarya!

@toddanglin

telerikwatch.com

[email protected]