0
There is time for REST<br />WCF REST Services<br />
Overview<br />What is REST<br />Rules and Guidelines<br />Hosting a REST Service in .NET<br />Consuming a REST Service wit...
What is REST?<br />Roy Fieldinghttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm<br /><ul><li>Client-Server
Stateless
Cachable
Layered System</li></li></ul><li>REST Constraints<br />Separation resource from representation<br />Uniform interface<br /...
HTTP Methods<br />
HTTP Methods<br />
HTTP Status Codes<br />
HTTP Messages<br />Request<br />GET http://localhost:1128/api?$skip=2&$top=2 HTTP/1.1<br />User-Agent: Fiddler<br />Host: ...
URIs<br />RPC (SOAP) Interface<br />http://example.com/CarsService/getYears<br />http://example.com/CarsService/getMakes<b...
URIs<br />RESTful Interface<br />No need to distinguish get/update/delete, that’s what the HTTP Method is for<br />Collect...
Return Types<br />XML<br />XHTML<br />ATOM Publishing Protocol<br />RSS<br />Custom (should contain hyperlinks)<br />JSON<...
WCF and REST<br />WCF 4 REST<br />REST endpoints<br />Uri templates for routing<br />WCF Hosting (Console, IIS, etc) etc.<...
WCF 4 REST, Web Api<br />Programming model for HTTP in WCF<br />Access HTTP from top to bottom<br />REST endpoints<br />Ur...
WCF REST contract<br />[ServiceContract]<br />publicinterfaceIAutomobileService<br />{<br />   [OperationContract]<br />  ...
Uri Templates<br />[ServiceContract]<br />public interface IAutomobileService<br />{<br />   [OperationContract]<br />   [...
Routing<br />staticvoidRegisterRoutes(RouteCollection routes)<br />{<br />routes.MapServiceRoute<SampleResource>("api");<b...
Consuming REST .NET<br />
WebRequest<br />varhttpRequest = (HttpWebRequest)WebRequest.Create(<br />			"http://localhost/myservice");<br /> <br />usi...
WebChannelFactory<br />[ServiceContract]<br />publicinterfaceITwitterService<br />{<br />    [OperationContract]<br />    ...
HttpClient<br />var sample = newSample();<br />using (var client = newHttpClient())<br />{<br />client.DefaultRequestHeade...
Tools<br />Fiddlerhttp://www.fiddler2.com/fiddler2/<br />Firebughttp://getfirebug.com<br />IEWatchhttp://www.iewatch.com/<...
Show me the code<br />
Implementations<br />OpenRastaOpenRasta brings the concept of REST to the .NET platform in ways that allow it to be deploy...
Books<br />
Upcoming SlideShare
Loading in...5
×

There is time for rest

1,152

Published on

Презентація підготовлена та проводиться Романом Калитою (Львів)

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

No Downloads
Views
Total Views
1,152
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "There is time for rest "

  1. 1. There is time for REST<br />WCF REST Services<br />
  2. 2. Overview<br />What is REST<br />Rules and Guidelines<br />Hosting a REST Service in .NET<br />Consuming a REST Service with .NET<br />Samples<br />Discussion<br />
  3. 3. What is REST?<br />Roy Fieldinghttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm<br /><ul><li>Client-Server
  4. 4. Stateless
  5. 5. Cachable
  6. 6. Layered System</li></li></ul><li>REST Constraints<br />Separation resource from representation<br />Uniform interface<br />Self-descriptive messages<br />Hypermedia as engine of application state<br />
  7. 7. HTTP Methods<br />
  8. 8. HTTP Methods<br />
  9. 9. HTTP Status Codes<br />
  10. 10. HTTP Messages<br />Request<br />GET http://localhost:1128/api?$skip=2&$top=2 HTTP/1.1<br />User-Agent: Fiddler<br />Host: localhost:1128<br />Accept: application/xml<br />Response<br />HTTP/1.1 200 OK<br />Cache-Control: private<br />Content-Length: 157<br />Content-Type: application/xml; charset=utf-8<br />Server: Microsoft-IIS/7.5<br />Date: Fri, 26 Aug 2011 18:51:22 GMT<br /><?xml version="1.0" encoding="utf-8"?><br /><Data /><br />
  11. 11. URIs<br />RPC (SOAP) Interface<br />http://example.com/CarsService/getYears<br />http://example.com/CarsService/getMakes<br />http://example.com/CarsService/getAutomobile<br />http://example.com/CarsService/updateAutomobile<br />http://example.com/CarsService/deleteAutomobile<br />
  12. 12. URIs<br />RESTful Interface<br />No need to distinguish get/update/delete, that’s what the HTTP Method is for<br />Collection<br />http://example.com/2011/Honda/<br />Resource<br />http://example.com/2011/Honda/Civic/2.0<br />
  13. 13. Return Types<br />XML<br />XHTML<br />ATOM Publishing Protocol<br />RSS<br />Custom (should contain hyperlinks)<br />JSON<br />Custom<br />
  14. 14. WCF and REST<br />WCF 4 REST<br />REST endpoints<br />Uri templates for routing<br />WCF Hosting (Console, IIS, etc) etc.<br />
  15. 15. WCF 4 REST, Web Api<br />Programming model for HTTP in WCF<br />Access HTTP from top to bottom<br />REST endpoints<br />Uri templates for routing<br />WCF Hosting (Console, IIS, etc) etc.<br />Http Client<br />Plug in any format / media type<br />Typeless JSON support<br />IQueryablesupport<br />
  16. 16. WCF REST contract<br />[ServiceContract]<br />publicinterfaceIAutomobileService<br />{<br /> [OperationContract]<br /> [WebGet(UriTemplate = "*")]<br />Message Get();<br /> [OperationContract]<br /> [WebInvoke(Method = "PUT", UriTemplate = "*")]<br />Message Put(Message data);<br />}<br />
  17. 17. Uri Templates<br />[ServiceContract]<br />public interface IAutomobileService<br />{<br /> [OperationContract]<br /> [WebGet(UriTemplate = "/{year}/{make}/{model}/{engine}")]<br />AutomobilesGetAutomobiles(string year, string make, <br />string model, string engine);<br />}<br />
  18. 18. Routing<br />staticvoidRegisterRoutes(RouteCollection routes)<br />{<br />routes.MapServiceRoute<SampleResource>("api");<br />}<br />voidApplication_Start(objectsender,EventArgs e)<br />{<br />RegisterRoutes(RouteTable.Routes);<br />} <br />
  19. 19. Consuming REST .NET<br />
  20. 20. WebRequest<br />varhttpRequest = (HttpWebRequest)WebRequest.Create(<br /> "http://localhost/myservice");<br /> <br />using (varupStream = httpRequest.GetRequestStream())<br />{<br />// some complicated logic to create the message<br />}<br /> <br />var response = httpRequest.GetResponse();<br />using (vardownStream = response.GetResponseStream())<br />{<br />// some complicated logic to handle the response message.<br />}<br />
  21. 21. WebChannelFactory<br />[ServiceContract]<br />publicinterfaceITwitterService<br />{<br /> [OperationContract]<br /> [WebInvoke(UriTemplate = "/friendships/create/{user}.xml")]<br />TwitterUserCreateFriendship(string user);<br />}<br /> <br />using (var factory = newWebChannelFactory<ITwitterService>(<br /> newUri("http://www.twitter.com/")))<br />{<br />factory.Credentials.UserName.UserName = username;<br />factory.Credentials.UserName.Password = password;<br />var proxy = factory.CreateChannel();<br />var user = proxy.CreateFriendship("userToFollow");<br />}<br />
  22. 22. HttpClient<br />var sample = newSample();<br />using (var client = newHttpClient())<br />{<br />client.DefaultRequestHeaders.Accept.Add(<br />newMediaTypeWithQualityHeaderValue("application/json"));<br />client.Post(<br /> "http://localhost/myservice", <br /> newObjectContent(typeof(Sample), <br /> sample, <br />Sample.JsonMediaType));<br />}<br />
  23. 23. Tools<br />Fiddlerhttp://www.fiddler2.com/fiddler2/<br />Firebughttp://getfirebug.com<br />IEWatchhttp://www.iewatch.com/<br />
  24. 24. Show me the code<br />
  25. 25. Implementations<br />OpenRastaOpenRasta brings the concept of REST to the .NET platform in ways that allow it to be deployed alongside ASP.NET and WCF components. http://trac.caffeine-it.com/openrasta/wiki/Doc<br />http://code.google.com/p/implementing-rest/wiki/ByLanguage<br />
  26. 26. Books<br />
  27. 27. Resources<br />WCF Web API<br /><ul><li>http://wcf.codeplex.com</li></ul>WCF Web APis: "There's a URI for That"<br /><ul><li>http://channel9.msdn.com/Events/MIX/MIX11/FRM14</li></ul>RFC HTTP <br /><ul><li>http://www.ietf.org/rfc/rfc2616.txt</li></ul>Implementing REST, small reference and list of frameworks<br /><ul><li>http://code.google.com/p/implementing-rest/</li></ul>REST on Wikipedia<br /><ul><li>http://en.wikipedia.org/wiki/REST</li></li></ul><li>
  1. A particular slide catching your eye?

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

×