0
Doing REST with new WCF Web API <br />Himanshu Desai<br />Senior Consultant - Readify<br />Discover. Master. Influence.<br />
Agenda<br />Web as Resource Oriented Architecture<br /><ul><li>Current Industry Trends</li></ul>Overview of REST<br />What...
Resource Oriented Architecture<br />3<br />Discover. Master. Influence.<br />
Current Industry Trends<br />A Move to cloud-based computing<br />A Migration away from SOAP<br />More browser based Apps<...
What is REST? <br />Representational State Transfer<br />Idea floated by Roy Fielding<br />Architecture Style (not a proto...
REST Constraints<br />Client - server<br />Stateless<br />Cacheable<br />Layered<br />Uniform interface<br />Discover. Mas...
REST Constraints<br />Uniform interface<br />Client - server<br />Stateless<br />Cacheable<br />Layered<br />Discover. Mas...
REST Benefits<br />Scalability of component interactions<br />Evolvability<br />Reach<br />Intermediary components to redu...
RESTful Services-1<br />A Traditional RPC based Service<br />Moving from Verb to Noun<br />Users<br />Bookmarks<br />Disco...
RESTful Services-2<br />Designing the Uri Template<br />An invidual user account<br />An individual bookmark<br />A user’s...
RESTful Services-2<br />11<br />Discover. Master. Influence.<br />
RESTful Services-3<br />Designing Resource Representation<br />Discover. Master. Influence.<br />12<br />
RESTful Services-4<br />Designing Resource Representation<br /><User><br />	< Email>aaron@pluralsight.com</Email><br />	<N...
GET Example<br />REQUEST<br />GET /index.html<br />Host: www.example.com<br />RESPONSE<br />HTTP/1.1 200 OK<br />Etag: „3f...
POST Example<br />POST /order HTTP/1.1<br />Host: amazon.net<br />Content-Type: application/xml<br />Content-Length: 216<b...
PUT Example<br />PUT /payment/1234 HTTP/1.1<br />Host: amazon.net<br />Content-Type: application/xml<br />Content-Length: ...
Central Principle<br />Existence of resource which is referenced with a global identifier (e.g. a image, document etc.)<br...
RESTful web services<br />Collection of data <br />Base URI e.g. http://ebay.com/items/1<br />Internet Media type of the d...
REST Using WCF<br />Discover. Master. Influence.<br />
Rest Support Comparison<br />Discover. Master. Influence.<br />20<br />
WCF Web API<br />HTTP is now a first class <br />Content negotiation<br />Automatic help pages<br />Service Routes<br />In...
Resource<br />Architecture<br />Op Handler2<br />Transport+Encoder<br />Message Handler 1 <br />Response<br />Discover. Ma...
Components<br />Content Negotiation<br />Central Configuration (Fluent API)<br />Http  Classes<br />Operation Handler Fact...
Classes for Request & Response<br /><ul><li>HttpRequestMessage
HttpResponseMessage
HttpContent
HttpClient</li></ul>Discover. Master. Influence.<br />24<br />
Content Negotiation<br />Support for Multiple Formats including an add-in model<br />if you want xml ,it gives xml and if ...
Demo<br />Content Negotiation<br />Discover. Master. Influence.<br />
Operation Handler Factory<br />Responsible for creating new instances of Media Type Formatters and Operation Handlers.<br ...
Operation Handler Factory<br />Request Pipeline<br />Response Pipeline<br />Operation Handler<br />Operation Handler<br />...
Message Handler Factory<br />Operation<br />Message Handler4<br />Message Handler3<br />Message Handler 1<br />Message Han...
Upcoming SlideShare
Loading in...5
×

Wcf rest api introduction

1,443

Published on

Presentation at DDDMelbourne.

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
1,443
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • http://msdn.microsoft.com/en-us/library/dd203052.aspx
  • Representational State TransferIdea floated by Roy FieldingArchitectural Style (not a protocol or spec and it is not restricted to HTTP)ConceptREST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests and return appropriate responses. Requests and responses are built around the transfer of representations of resources. A resource can be essentially any coherent and meaningful concept that may be addressed. A representation of a resource is typically a document that captures the current or intended state of a resource.At any particular time, a client can either be in transition between application states or &quot;at rest&quot;. A client in a rest state is able to interact with its user, but creates no load and consumes no per-client storage on the servers or on the network.The client begins sending requests when it is ready to make the transition to a new state. While one or more requests are outstanding, the client is considered to be in transition. The representation of each application state contains links that may be used next time the client chooses to initiate a new state transition.REST was initially described in the context of HTTP, but is not limited to that protocol. RESTful architectures can be based on other Application Layer protocols if they already provide a rich and uniform vocabulary for applications based on the transfer of meaningful representational state. RESTful applications maximize the use of the pre-existing, well-defined interface and other built-in capabilities provided by the chosen network protocol, and minimize the addition of new application-specific features on top of it.
  • Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • In 3.5 &amp; 4.0New Attributes (WebGet/WebInvoke)New Binding (WebHttpBinding)Routing, help pages etc.Partial Support for Content negotiationIn .NET 4, Out of box XML and Json were supported. If you need to support other types , you need to extent webcontenttypemapper.Service routes- provides compile time checking. Integrates with ASP.NET RoutingYou host service which is then available as a route.WCF Web APIHTTP is now a first class Content negotiationAutomatic help pagesService RoutesIntegration with ASP.NET CachingReach any client (Browser, Devices, Silverlight, Desktop)
  • Service routes- provides compile time checking. Integrates with ASP.NET RoutingYou host service which is then available as a route.
  • Transcript of "Wcf rest api introduction"

    1. 1. Doing REST with new WCF Web API <br />Himanshu Desai<br />Senior Consultant - Readify<br />Discover. Master. Influence.<br />
    2. 2. Agenda<br />Web as Resource Oriented Architecture<br /><ul><li>Current Industry Trends</li></ul>Overview of REST<br />What is REST? <br />REST Constraints<br />REST Benefits<br />REST using WCF<br />REST Support in WCF<br />WCF Web API <br />Discover. Master. Influence.<br />
    3. 3. Resource Oriented Architecture<br />3<br />Discover. Master. Influence.<br />
    4. 4. Current Industry Trends<br />A Move to cloud-based computing<br />A Migration away from SOAP<br />More browser based Apps<br />Adoption of REST<br />Other standards like OAuth, WebSockets<br />Discover. Master. Influence.<br />4<br />
    5. 5. What is REST? <br />Representational State Transfer<br />Idea floated by Roy Fielding<br />Architecture Style (not a protocol or spec and it is not restricted to HTTP)<br />Discover. Master. Influence.<br />5<br />
    6. 6. REST Constraints<br />Client - server<br />Stateless<br />Cacheable<br />Layered<br />Uniform interface<br />Discover. Master. Influence.<br />6<br />
    7. 7. REST Constraints<br />Uniform interface<br />Client - server<br />Stateless<br />Cacheable<br />Layered<br />Discover. Master. Influence.<br />7<br />
    8. 8. REST Benefits<br />Scalability of component interactions<br />Evolvability<br />Reach<br />Intermediary components to reduce latency, enforce security and encapsulate legacy systems<br />Discover. Master. Influence.<br />8<br />
    9. 9. RESTful Services-1<br />A Traditional RPC based Service<br />Moving from Verb to Noun<br />Users<br />Bookmarks<br />Discover. Master. Influence.<br />9<br />
    10. 10. RESTful Services-2<br />Designing the Uri Template<br />An invidual user account<br />An individual bookmark<br />A user’s collection of private/public bookmark<br />Collection of all public bookmarks<br />Applying the Uniform HTTP Interface<br />Discover. Master. Influence.<br />10<br />
    11. 11. RESTful Services-2<br />11<br />Discover. Master. Influence.<br />
    12. 12. RESTful Services-3<br />Designing Resource Representation<br />Discover. Master. Influence.<br />12<br />
    13. 13. RESTful Services-4<br />Designing Resource Representation<br /><User><br /> < Email>aaron@pluralsight.com</Email><br /> <Name>Aaron Skonnard</Name><br /></User><br />Supporting Alternate Representation<br />?tag={tag}&format=json<br />{username}?tag={tag}&format=json<br />users/{username}?format=json<br />users/{username}/profile?format=json<br />Security Consideration<br />Providing Resource Metadata<br />Avoiding RPC Tendencies<br />13<br />Discover. Master. Influence.<br />
    14. 14. GET Example<br />REQUEST<br />GET /index.html<br />Host: www.example.com<br />RESPONSE<br />HTTP/1.1 200 OK<br />Etag: „3f80f-1b6-3e1cb03b”<br />Content-Type: text/html; charset=UTF-8<br />l<br />Discover. Master. Influence.<br />14<br />
    15. 15. POST Example<br />POST /order HTTP/1.1<br />Host: amazon.net<br />Content-Type: application/xml<br />Content-Length: 216<br /><order xmlns="http://schemas.amazon.net/order"><br /><drink>latte</drink><br /></order><br />201 Created<br />Location: http://amazon.net/order/1234<br />ContentType: application/xml<br /><order xmlns="http://schemas.amazon.net/order"><br />...<br />l<br />Discover. Master. Influence.<br />15<br />
    16. 16. PUT Example<br />PUT /payment/1234 HTTP/1.1<br />Host: amazon.net<br />Content-Type: application/xml<br />Content-Length: 216<br /><payment xmlns="http://schemas.amazon.net/order"><br /><cardNumber>...</cardNumber><br /></order><br />200 OK<br />ContentType: application/vnd.amazon+xmlxmlns="http://schemas.amazon.net/order"><br /><drink>Latte</drink><br /><link href=„payment/1234” rel=„http://relations.amazon.net/payment”/><br /></order><br />l<br />Discover. Master. Influence.<br />16<br />
    17. 17. Central Principle<br />Existence of resource which is referenced with a global identifier (e.g. a image, document etc.)<br />Communicate via a standard interface (e.g. HTTP)<br />Exchange representations of these resources (HTML.XML,JSON etc.)<br />Discover. Master. Influence.<br />17<br />
    18. 18. RESTful web services<br />Collection of data <br />Base URI e.g. http://ebay.com/items/1<br />Internet Media type of the data supported by the web service. (JSON,XML etc.)<br />Set of operation supported by the web service using HTTP methods (POST,GET,PUT or DELETE)<br />Discover. Master. Influence.<br />18<br />
    19. 19. REST Using WCF<br />Discover. Master. Influence.<br />
    20. 20. Rest Support Comparison<br />Discover. Master. Influence.<br />20<br />
    21. 21. WCF Web API<br />HTTP is now a first class <br />Content negotiation<br />Automatic help pages<br />Service Routes<br />Integration with ASP.NET Caching<br />Reach any client <br /> (Browser, Devices, Silverlight, Desktop)<br />Discover. Master. Influence.<br />21<br />
    22. 22. Resource<br />Architecture<br />Op Handler2<br />Transport+Encoder<br />Message Handler 1 <br />Response<br />Discover. Master. Influence.<br />22<br />Dispatcher<br />GetById?<br />GetById?<br />Op Handler 3<br />Op Handler 4<br />Op Handler 1<br />Message Handler 2<br />Request<br />
    23. 23. Components<br />Content Negotiation<br />Central Configuration (Fluent API)<br />Http Classes<br />Operation Handler Factory<br />Error Handler<br />Message Handler Factory(Channel Level)<br />Discover. Master. Influence.<br />23<br />
    24. 24. Classes for Request & Response<br /><ul><li>HttpRequestMessage
    25. 25. HttpResponseMessage
    26. 26. HttpContent
    27. 27. HttpClient</li></ul>Discover. Master. Influence.<br />24<br />
    28. 28. Content Negotiation<br />Support for Multiple Formats including an add-in model<br />if you want xml ,it gives xml and if you want Json, it gives Json<br />Discover. Master. Influence.<br />25<br />
    29. 29. Demo<br />Content Negotiation<br />Discover. Master. Influence.<br />
    30. 30. Operation Handler Factory<br />Responsible for creating new instances of Media Type Formatters and Operation Handlers.<br />Media Type Formatter <br />Operation Handler - an abstract base class used to create transfer a set of input into a set of output<br />Discover. Master. Influence.<br />27<br />
    31. 31. Operation Handler Factory<br />Request Pipeline<br />Response Pipeline<br />Operation Handler<br />Operation Handler<br />Operation Handler<br />Operation Handler<br />Operation Handler<br />Operation Handler<br />Dispatch<br />Discover. Master. Influence.<br />28<br />
    32. 32. Message Handler Factory<br />Operation<br />Message Handler4<br />Message Handler3<br />Message Handler 1<br />Message Handler2<br />Discover. Master. Influence.<br />29<br />
    33. 33. Query Composition<br />Support for OData like query support<br />http://localhost/AlbumService/albums?$Top=5<br />http://localhost/AlbumService/albums?$Top=5&$OrderBy=Title<br />Discover. Master. Influence.<br />30<br />
    34. 34. Consuming RESTful Services<br />Consuming with Javascript<br />Consuming with WCF<br />31<br />Discover. Master. Influence.<br />
    35. 35. Consuming Web API with Javascript<br />32<br />Discover. Master. Influence.<br />
    36. 36. HttpClient<br />Helps you access web resources using Linq<br />var client = new HttpClient(address);<br /> var personQuery = client.CreateQuery<Person>();<br /> var results = personQuery.ExecuteAsync().ContinueWith(p =><br /> {<br />//Dosomething here<br /> });<br />Discover. Master. Influence.<br />33<br />
    37. 37. Demo<br />Query Composition & HttpClient<br />Discover. Master. Influence.<br />
    38. 38. Questions?<br />Discover. Master. Influence.<br />
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×