REST and ASP.NET Web API (Tunisia)

5,270 views

Published on

Slides from my session on REST and ASP.NET Web API at the Euricom Tunisia trip.

Published in: Technology
  • Be the first to comment

REST and ASP.NET Web API (Tunisia)

  1. 1. REST &ASP.NET Web API By @JefClaes
  2. 2. REST
  3. 3. The acronymREpresentational State Transfer
  4. 4. REST is NOT...• „Webservices using JSON‟• A protocol• A design pattern
  5. 5. REST is...“An architectural style for buildingdistributed hypermedia systems.”
  6. 6. In theory... REST isn‟t limitedto a single message protocol.
  7. 7. But in practice...It‟s all about HTTP.
  8. 8. So now you wonder..Haven‟t we been successfully buildingweb services using SOAP and HTTP for over 10 years ?
  9. 9. BASIC CONCEPTS
  10. 10. Resources• An entity, item, or just a thing you want to expose.• REST is Resource Oriented. A bank
  11. 11. IdentifiersSomething that identifies a resource.BIC (= Bank Identifier Code): KREDBEBBURI: http://myapi.com/bank/KREDBEBB
  12. 12. RepresentationsView on a resource‟s state at an instant in time.XML: JSON: Other:<Bank> { • Images <BIC>KREDBEBB</BIC> "BIC":"123“, • CSV <Name>KBC</Name> “Name”:”KBC” • Custom</Bank> } • ...
  13. 13. VerbsActions on a resource.Read, Update, Delete, AddGET, PUT, DELETE, POST
  14. 14. HypermediaHATEOAS: Hypermedia as the engine of application stateLinking your API together
  15. 15. Architecture of the WEBARCHITECTURAL VALUES
  16. 16. Scalability and performanceYes, text-based, synchronous, request-responsecan be performant.• Stateless• Caching
  17. 17. Loose coupling• No transactions• No state• No guarantees• HATEOAS• No specific technology stack
  18. 18. Consistency and UniformityEverybody knows how to use HTTP – Constraints – Well understood semantics
  19. 19. LEFT-OVERS
  20. 20. Richardson‟s Maturity Model Level 0: POX Level 1: Resources Level 2: HTTP verbsLevel 3: Hypermedia
  21. 21. Questions?
  22. 22. ASP.NET WEBAPI
  23. 23. What? .NET (4.0) HTTP frameworkfor building RESTful services.
  24. 24. When?• HTTP Services (WCF)• AJAX back-ends
  25. 25. The server
  26. 26. Options• ASP.NET MVC – Click, click, click• SelfHost
  27. 27. Selfhost
  28. 28. PackagesMicrosoft.AspNet.WebApi.SelfHost
  29. 29. Starting
  30. 30. Simple CRUD
  31. 31. Creating a controller
  32. 32. Creating a controller
  33. 33. Without conventions• Attributes [HttpGet]• [NonAction]
  34. 34. The Client
  35. 35. PackagesMicrosoft.AspNet.WebApi.Client
  36. 36. POST and GET
  37. 37. Exception handling
  38. 38. Default behaviour & IncludeErrorDetailPolicy• By default 500 Internal Server Error
  39. 39. HttpResponseException
  40. 40. ErrorFilters
  41. 41. Content negotiation
  42. 42. XML/JSONSupported out of the box:• text/xml• application/json (NewtonSoft)
  43. 43. Custom formatters
  44. 44. Custom formatters
  45. 45. HTTPMessagehandlers
  46. 46. HTTP intermediaries
  47. 47. DelegatingHandler
  48. 48. DelegatingHandler
  49. 49. IoC
  50. 50. IDependencyResolver
  51. 51. IDependencyResolver
  52. 52. Testing
  53. 53. Unit testig
  54. 54. Integration testing in-memory
  55. 55. Summary• REST – Concepts – Architectual values – Left overs• ASP.NET Web API – Server/client – Exception handling – Content negotiation – Message handlers – IoC – Testing
  56. 56. Questions

×