Presentation is loading. Please wait.

Presentation is loading. Please wait.

REST &.NET James Crisp.NET Practice Lead ThoughtWorks Australia.

Similar presentations


Presentation on theme: "REST &.NET James Crisp.NET Practice Lead ThoughtWorks Australia."— Presentation transcript:

1 REST &.NET James Crisp.NET Practice Lead ThoughtWorks Australia

2 James Crisp

3

4 The Web

5 *-ilities

6 Scalability

7 Recoverability & Reliability

8 Security

9 Discoverability

10

11 How to bring to Web services?

12 Tunneling RPC URLs POX SOAP & WS-*

13 REpresentational State Transfer

14

15 REST contributes... the rationale behind the modern Web's software architecture Roy Fielding

16 Resources e.g. Person, Car, Post

17 Representations Bill Gates m

18

19 Addressability

20 Uniform Interface

21 GET POST HEAD PUT DELETE OPTIONS Support

22 GET GET /people/joe_citizen HTTP/1.1 Host: mysite.com Accept: application/xml

23 Response 200 OK Content-Type: application/xml Last-Modified: :00.. Joe Citizen 42 m

24 HEAD HEAD /people/joe_citizen HTTP/1.1 Host: mysite.com 200 OK Content-Type: application/xml Last-Modified: :00.. ETag: a32daf15-b33da2a4d Response

25 POST POST /people HTTP/1.1 Content-Type: text/xml Host: mysite.com.... Tina Jones 25 F

26 Response 201 CREATED Location: /people/tina_jones (optionally with body)

27 PUT PUT /people/tina_jones HTTP/1.1 Content-Type: text/xml Host: mysite.com.... Tina Jones 24 F

28 Response 200 OK Location: /people/tina_jones (optionally with body)

29 DELETE DELETE /people/joe_citizen HTTP/1.1 Host: mysite.com 200 OK Content-Type: application/xml joe_citizen Response

30 OPTIONS OPTIONS /people HTTP/1.1 Host: mysite.com 200 OK Allowed: GET,HEAD,POST Response

31 Status Codes

32 2xx = All good 200 – OK 201 – Created

33 3xx = Redirect 301 – Moved permanently 307 – Temporary redirect 304 – Not modified (ie, see cache)

34 4xx = Client error 400 – Bad request 401 – Unauthorized 403 – Forbidden 405 – Method not allowed 409 – Conflict

35 5xx = Server error 500 – Internal server error

36 Headers

37 Content-Type: text/html application/xml image/jpeg....

38 WWW-Authenticate: Authorization:

39 Last-Modified: If-Modified-Since: ETag: If-None-Match:

40 Location:

41 Describe your services?

42 URI Templates

43 Start URL + Links https://bank.com/accounts/ Tina Jones

44 Microformats Tina Jones

45 State Management Search google.com/ search?q=rest google.com/search?q=rest& start=10 Next Page Searching Searched More Results

46 Data Format?

47 XHTML Accounts Tina Jones.....

48 JSON { "account_name": "Tina Jones", "links": {"history": "/tjones/history"} }

49

50 Framework

51 Ordering Pizza

52 GET / HTTP/1.1 Host: epizza.com Content-Type: application/xml

53 Response 200 OK Location: Content-Type: application/xml Content-Length:... Welcome!

54 Let's see the menu! GET /menu HTTP/1.1 Host: epizza.com Content-Type: application/xml

55 200 OK Location: Menu Response

56 Ordering time! POST /orders HTTP/1.1 Host: epizza.com Content-Type: application/xml Content-Length:...

57 201 Created Location: Content-Type:... Place Order Response

58 Beer with that?

59 OPTIONS /orders/413 HTTP/1.1 Host: epizza.com 200 OK Allowed: GET, HEAD, POST, PUT

60 Add Beer POST /orders/413 HTTP/1.1 Host: epizza.com Content-Type: application/xml Content-Length:...

61 200 OK Location: Content-Type:... Response

62 Destination Address PUT /orders/413/address HTTP/1.1 Host: epizza.com Content-Type: application/xml Content-Length: Rue Rd Potts Point

63 Destination Response 200 OK Host: epizza.com Content-Type: application/xml Content-Length: Rue Rd Potts Point

64 200 OK Location: Content-Type:... GET /orders/413

65

66 Can we? OPTIONS /orders/413 HTTP/1.1 Host: epizza.com 200 OK Allowed: GET, HEAD

67 Too late!

68

69 Back at the ePizza Kitchen..

70 GET /orders

71 Implementation

72 Client var request = (HttpWebRequest) WebRequest.Create(URL); request.Method request.ContentType request.GetRequestStream() var response = (HttpWebResponse)request.GetResponse(); response.StatusCode response.Headers response.GetResponseStream()

73

74 Server

75 IHttpHandler public class RestHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/xml"; if (context.Request.HttpMethod == "GET") { context.Response.Write("... "); }

76 WCF REST [ServiceContract] public interface IPizzaService { [WebGet(UriTemplate="/orders/{orderId}")] [OperationContract] Order GetOrder(int orderId); }

77 Status codes? Headers? Links? Microformats?

78 ASP.NET MVC

79 Routing Table Controller Method ModelView

80 Routes In GlobalApplication : HttpApplication void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "AddToOrder", "orders/{id}", new { controller = "Orders", action = "AddToOrder" }, new { httpMethod = new HttpMethodConstraint("POST")});... }

81 Controller public class OrdersController : Controller { public ActionResult AddToOrder(int id) { var order = Order.Load(id); var itemToAdd = CreateMenuItemFromRequest(); order.Items.Add(itemToAdd); order.Save(); // response.StatusCode = 200; return View(order); }

82 Model public class Order { public MenuItem[] Items { get {... }; } public Address DeliveryAddress { get; set; } }

83 View " />

84 MVC REST Wrinkles

85

86 See also... Slides & Code MVC RESTful Web Services

87 - web - bridge - web - defibrillator - padlocks - ws* stack - tunnel - fielding - bill gates - network plugs - speedometers - Petco explosion - letter - Eiffel tower - pizza restaurant - pepperoni pizza - corona - salad pizza boxes – REST book Image References

88 Questions?


Download ppt "REST &.NET James Crisp.NET Practice Lead ThoughtWorks Australia."

Similar presentations


Ads by Google