Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How...

23
Creating a RESTful API with WCF Aaron Sloman, speakTECH Haider Sabri, speakTECH

Transcript of Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How...

Page 1: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Creating a RESTful API with WCFAaron Sloman, speakTECHHaider Sabri, speakTECH

Page 2: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

About this presentation…

BackgroundREST (Representational State Transfer)

What does it mean to be RESTful?Why REST?

WCFHow does WCF support REST?What are the pieces we need to add?

ChessA RESTful Chess API

Page 3: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Background

Open Your API – 2005MySpace API roadmapWhere are we today ?

developer.myspace.com

Page 4: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Requirements for the Service

Public interface for 3rd party clients and partners to view, add, update, delete data.Easily consumable by any clientFollows established industry standardsNeeds to be highly scalableSupports different data interchange formatsModerately securable

Page 5: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Solution

Test’s we did….

WCFREST

Page 6: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Resource Oriented ArchitectureWhat does it mean to be RESTful?Power combo: URI and HTTP Method

Addressable, hierarchical URIs represent the entities or objects on your APIHTTP Method represents the action to be taken on the resource

Connectedness and DiscoverabilityLike the Web, Http Responses contain links to other resources

Roy Fielding dissertation http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

Page 7: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Why REST?

Benefits of REST for Web APIsLow barrier of entryROA follows Web Semantics…convenient for Web Service APIs.Flexibility in Response formats

REST is best choice when creating a general API when clients are unknown

Page 8: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

A RESTful API in Action

demo

Page 9: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

WCF Support for ROAThe “Web Programming Model”

URI Templates & WebGet/WebInvokeAttribute based definitions of URI template and HTTP method provide mapping of incoming request URIs to methods

WebHttpBindingThe binding that enables above

WebOperationContextFor more information:

Building Applications and Services with .NET Framework 3.5San Polo 3501A, M10:15 AM March 6th

Page 10: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

RESTChess behind the scenes…RESTChess.com

demo

Page 11: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

The pieces we need to addThe 20%

Flexible URIsBridging Low REST clientsRequest Authentication via Digital SigningExtending WebOperationContextMultiple Representation FormatsRESTful Exception Handling

Page 12: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

URI Template shortcomingsProblems…

Service .svc extensionRequired when hosting a WCF service in IIS

Can’t use custom extensions in templates

What if I want to let the URI extension define the representation format?

Page 13: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

URI Template shortcomingsSolutions…

Use URL Rewriter implemented as an HttpModule

Add .svc service file to incoming request URIUse extension format in path hierarchy and rewrite URI accordingly

Page 14: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

URLRewriting via IIS7

demo

Page 15: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

High/Low REST with the same service

High: support for full set of HTTP methodsLow: only support GET and POSTAllow clients to override HTTP method

Using X-HTTPMethodOverride headerUse of _method query parameter

Extending WCF…Channels to the Rescue

Page 16: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

High/Low REST

Extending WCF via Custom Channel

demo

Page 17: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Request AuthenticationOAuth

Introducing OAuthStandards based API authentication

Standard access delegation between Consumer and ProviderStandard digital signing mechanismoauth.net

Page 18: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Request AuthenticationOAuth

WCF Custom Channels to the rescue again

Channel will authenticate request before method dispatch

Extend Context with application data

Page 19: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

OAuth

Extending WCF via Custom Channel

demo

Page 20: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

RIA consumes RestChess

demo

Page 21: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

Summary

MySpace Development Platform is RESTfulWCF is a powerful web API development platformWCF has great extension pointsAll demo source available at RestChess.com

MySpace API’s are availableVisit developer.myspace.com

Page 22: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after

the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 23: Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.