Your SlideShare is downloading. ×
0
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Rest and the WCF Web API
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Rest and the WCF Web API

2,998

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,998
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
42
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. REST and the WCF Web API <br />Getting started with REST services and the WCF Web API<br />Maurice de Beijer<br />
  • 2. Objectives<br />What are REST services<br />Why REST instead of SOAP<br />The WCF Web API framework<br />The next webinar on the 25th of October is about creating HTML5/JavaScript clients for REST services<br />
  • 3. What are REST services<br />Representational State Transfer<br />A way of creating web services<br />Not using the WS-* SOAP specifications<br />All about resources<br />Not about calling functions, RPC<br />Embraces HTTP<br />Not just a way of getting data across the wire<br />Leverages the structure of the Internet<br />URLS<br />MIME Media Types<br />HTTP Methods<br />Caching<br />Security<br />
  • 4. The origin of REST<br />Architectural Styles and the Design of Network-based Software Architectures<br />By Roy Thomas Fielding<br />Chapter 5<br />One of the authors of the HTTP specification<br />
  • 5. Why are REST services popular<br />Almost every platform supports consuming them<br />All you need is an HTTP client stack<br />Many services are build around resources<br />CRUD style<br />Enables very scalable services<br />Build around the technology that powers the Internet<br />
  • 6. The WCF Web API framework<br />On CodePlex<br />http://wcf.codeplex.com/wikipage?title=WCF%20HTTP<br />Use NuGet from within Visual Studio 2010<br />http://nuget.org/<br />Current version 0.5<br />Much better than the original WCF support for REST<br />But doesn’t replace it<br />
  • 7. The resource URL<br />The URL is the key to a resource<br />http://bookshop.com/books (The collection of books)<br />http://bookshop.com/books/12345(An individual book)<br />A given URL always returns the same resource<br />Deleting one resource doesn’t change the URL of another resource<br />But a resource can have multiple URL’s<br />http://bookshop.com/orders/12345<br />http://bookshop.com/customers/12345/orders/12345<br />
  • 8. Different request/response formats<br />Uses standard HTTP MIME Media Types<br />http://www.iana.org/assignments/media-types/index.html<br />Content Negotiation<br />The client specifies a list of acceptable media types<br />The server chooses the best supported media type to return<br />XML<br />Good general purpose data format<br />JSON<br />Optimised for usage with JavaScript clients<br />Custom formats<br />Use one of the many IANA types<br />Define your own<br />Normally prefixed with vnd.<br />Example: application/vnd.wordperfect<br />
  • 9. HTTP Status codes<br />Tell the client application what happened<br />Successful 2xx<br />200 OK<br />201 Resource created<br />Redirection 3xx<br />301 Moved Permanently<br />Client Error 4xx<br />400 Bad request<br />404 Not found<br />Server Error 5xx<br />500 Internal Server Error<br />503 Service Unavailable<br />
  • 10. HTTP GET Method<br />No side effects<br />Can retrieve it as often as you like<br />Allows for caching<br />Request may never get to the server<br />Makes the web as scalable as it is<br />Use Accept header to specify the acceptable media type<br />Multiple types are supported<br />Examples:<br />Accept: application/xml<br />Accept: application/json<br />Accept: image/jpeg, image/*; q=0.5<br />
  • 11. Other HTTP Methods<br />POST<br />Creates new resource<br />Returns the URL to the created resource<br />PUT or PATCH<br />Replaces/updates resource<br />Idempotent<br />PATCH only replaces a part of the resource<br />DELETE<br />Removes resource<br />Idempotent<br />
  • 12. Microformats<br />Enable a much smarter client application<br />Embed allowed actions with a resource<br />Client can update the UI based on the resource<br />OData is a good example<br />Based on AtomPub<br />http://www.odata.org<br />Roll your own<br />Or reuse an existing one from IANA<br />Set the content-type<br />Use your own application/vnd.xxx<br />
  • 13. Rest is not perfect<br />No metadata<br />Little tooling in Visual Studio 2010<br />It’s harder than it seems<br />There is no official REST standard<br />There are many strong opinions about what is REST and what is not<br />
  • 14. Usefull resources<br />Essential Windows Communication Foundation 4 Training<br />http://www.develop.com/training-course/windows-communication-foundation-wcf<br />Hypertext Transfer Protocol -- HTTP/1.1<br />http://tools.ietf.org/html/rfc2616<br />The Atom Syndication Format<br />http://tools.ietf.org/html/rfc4287<br />The Atom Publishing Protocol<br />http://tools.ietf.org/html/rfc5023<br />Open Data Protocol (OData)<br />http://www.odata.org<br />WCF Web API Contrib<br />http://webapicontrib.codeplex.com<br />Fiddler<br />http://www.fiddler2.com<br />
  • 15. Summary<br />REST is all about resources<br />CRUD actions<br />REST embraces HTTP and the web<br />HTTP isn’t just a means of moving bits<br />REST services are a good way to build scalable services<br />Build on the infrastructure of the web<br />REST allows for very flexible services<br />You control every part of the message<br />

×