REST and ASP.NET Web API (Milan)

5,926 views

Published on

REST and ASP.NET Web API (Milan)

  1. 1. REST & ASP.NET Web API @JefClaes
  2. 2. Thanks to the sponsors
  3. 3. about/jefclaes@jefclaeshttp://jefclaes.be
  4. 4. REST
  5. 5. The acronymREpresentational State Transfer
  6. 6. REST is NOT...• ‘Webservices using JSON’• A protocol• A design pattern
  7. 7. REST is..“An architectural style for buildingdistributed hypermedia systems.”
  8. 8. In theory... REST isn’t limited to asingle message protocol.
  9. 9. But in practice...It’s all about HTTP.
  10. 10. So now you wonder..Haven’t we been successfully building web services using SOAP and HTTP for over 10 years ?
  11. 11. BASIC CONCEPTS
  12. 12. Resources• An entity, item, or just a thing you want to expose.• REST is Resource Oriented.
  13. 13. Resources
  14. 14. Resources
  15. 15. Resources
  16. 16. Resources
  17. 17. IdentifiersSomething that identifies a resource.ID: 1URI: http://batman.com/api/batresource/1
  18. 18. RepresentationsView on a resource’s state at an instant in time.XML: JSON: Other:<BatResource> { • Images <Id>1</Id> "Id":"1", • CSV <Description> "Description":"Bataran • Custom Batarang g", • ... </Description> "Quantity":1 <Quantity>1</Quantity> }</BatResource>
  19. 19. VerbsActions on a resource.Create Read Update DeletePOST GET PUT DELETE
  20. 20. HypermediaHATEOAS: Hypermedia as the engine of application stateLinking your API together{ "Id":"1", "Description":"Batarang", “Quantity":1, “Links": { "Rel":"Next", "Href":"http://localhost:8080/api/batresource/2" }}
  21. 21. HypeRRRRRRRmedia• Relations• Embedded resources• Reference data• Redistribution of effort• Reduction of payload size• Reflow• Restriction of functionality
  22. 22. Architecture of the WEBARCHITECTURAL VALUES
  23. 23. Scalability and performanceYes, text-based, synchronous, request-responsecan be performant.• Stateless• Caching
  24. 24. Loose coupling• No transactions• No state• No guarantees• HATEOAS• No specific technology stack
  25. 25. Consistency and UniformityEverybody knows how to use HTTP –Constraints –Well understood semantics
  26. 26. LEFT-OVERS
  27. 27. Richardson’s Maturity Model Level 0: POX Level 1: Resources Level 2: HTTP verbs Level 3: Hypermedia
  28. 28. ASP.NET WEBAPI
  29. 29. What? .NET HTTP framework (4.0)for building RESTful services.
  30. 30. When?• HTTP Services (WCF)• AJAX back-ends
  31. 31. The server
  32. 32. Options• WebHost – ASP.NET MVC: Click, click, click• SelfHost
  33. 33. Starting
  34. 34. Mapping Web API to REST concepts
  35. 35. A resource
  36. 36. A resource
  37. 37. Identifiers
  38. 38. Identifiers
  39. 39. Verbs
  40. 40. Verbs
  41. 41. Representations
  42. 42. Representationsapplication/jsontext/xml
  43. 43. Representations
  44. 44. Hypermedia
  45. 45. Hypermedia
  46. 46. The Client
  47. 47. PackageMicrosoft.AspNet.WebApi.Client
  48. 48. Verbs and asynchrony
  49. 49. Summary• REST – Concepts – Architectual values – Left overs• ASP.NET Web API – Server – Client
  50. 50. There is moreSlides and source on http://jefclaes.beExtensibility?• Next session (Raffaele Rialdi)• http://github.com/JefClaes/aspnet-webapi-samples-tunisia
  51. 51. Please rate this sessionScan the code, go online, rate this session

×