Creating a RESTful API with Windows Communication Foundation
-
Upload
goodfriday -
Category
Technology
-
view
1.010 -
download
1
description
Transcript of Creating a RESTful API with Windows Communication Foundation
Creating a RESTful API with WCFAaron Sloman, speakTECHHaider Sabri, speakTECH
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
Background
Open Your API – 2005MySpace API roadmapWhere are we today ?
developer.myspace.com
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
Solution
Test’s we did….
WCFREST
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
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
A RESTful API in Action
demo
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
RESTChess behind the scenes…RESTChess.com
demo
The pieces we need to addThe 20%
Flexible URIsBridging Low REST clientsRequest Authentication via Digital SigningExtending WebOperationContextMultiple Representation FormatsRESTful Exception Handling
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?
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
URLRewriting via IIS7
demo
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
High/Low REST
Extending WCF via Custom Channel
demo
Request AuthenticationOAuth
Introducing OAuthStandards based API authentication
Standard access delegation between Consumer and ProviderStandard digital signing mechanismoauth.net
Request AuthenticationOAuth
WCF Custom Channels to the rescue again
Channel will authenticate request before method dispatch
Extend Context with application data
OAuth
Extending WCF via Custom Channel
demo
RIA consumes RestChess
demo
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
© 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.