Creating a RESTful API with WCF

Download Report

Transcript Creating a RESTful API with WCF

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 to add?
Chess
A RESTful Chess API
Open Your API – 2005
MySpace API roadmap
Where are we today ?
developer.myspace.com
Public interface for 3rd party clients and
partners to view, add, update, delete data.
Easily consumable by any client
Follows established industry standards
Needs to be highly scalable
Supports different data interchange formats
Moderately securable
Test’s we did….
WCF
REST
What does it mean to be RESTful?
Power combo: URI and HTTP Method
Addressable, hierarchical URIs represent the
entities or objects on your API
HTTP Method represents the action to be
taken on the resource
Connectedness and Discoverability
Like the Web, Http Responses contain links to
other resources
Roy Fielding dissertation
http://www.ics.uci.edu/~fielding/pubs/dissert
ation/top.htm
Benefits of REST for Web APIs
Low barrier of entry
ROA 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
The “Web Programming Model”
URI Templates & WebGet/WebInvoke
Attribute based definitions of URI template and HTTP
method provide mapping of incoming request URIs to
methods
WebHttpBinding
The binding that enables above
WebOperationContext
For more information:
Building Applications and Services with .NET Framework 3.5
San Polo 3501A, M10:15 AM March 6th
The 20%
Flexible URIs
Bridging Low REST clients
Request Authentication via Digital Signing
Extending WebOperationContext
Multiple Representation Formats
RESTful Exception Handling
Problems…
Service .svc extension
Required 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?
Solutions…
Use URL Rewriter implemented as an
HttpModule
Add .svc service file to incoming request URI
Use extension format in path hierarchy and
rewrite URI accordingly
High: support for full set of HTTP methods
Low: only support GET and POST
Allow clients to override HTTP method
Using X-HTTPMethodOverride header
Use of _method query parameter
Extending WCF…Channels to the Rescue
OAuth
Introducing OAuth
Standards based API authentication
Standard access delegation between
Consumer and Provider
Standard digital signing mechanism
oauth.net
OAuth
WCF Custom Channels to the rescue again
Channel will authenticate request before
method dispatch
Extend Context with application data
MySpace Development Platform is RESTful
WCF is a powerful web API development
platform
WCF has great extension points
All demo source available at
RestChess.com
MySpace API’s are available
Visit 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.