Intro to Hypermedia APIs

2,392 views

Published on

An introduction to Hypermedia APIs from software developer Eric Oestrich.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,392
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Intro to Hypermedia APIs

  1. 1. Introduction toHypermedia APIs Eric Oestrich @ericoestrich oestri.ch smartlogicsolutions.com
  2. 2. What is a Hypermedia API?
  3. 3. RESTREpresentational State Transfer
  4. 4. Relies Heavily on HTTP● Methods and URI● Media Types● Client Server
  5. 5. Relies Heavily on HTTP (Cont)● Stateless● Caching● Uniform Interface (HATEOAS)
  6. 6. Methods and URIs
  7. 7. Five RoutesGET /ordersPOST /ordersGET /orders/:idPUT /orders/:idDELETE /orders/:id
  8. 8. GET /orders List of orders
  9. 9. POST /orders Create an order
  10. 10. GET /orders/:id View a single order
  11. 11. PUT /orders/:idReplace or create an order
  12. 12. DELETE /orders/:id Delete an order
  13. 13. A bit about HTTP Verbs
  14. 14. GETRetrieve a resource
  15. 15. POSTMost generic
  16. 16. PUTReplace or Create Not partial
  17. 17. DELETEDelete a resource
  18. 18. PATCHUpdate partially Must be a diff
  19. 19. Media Types
  20. 20. Formats● JSON● XML● XHTML
  21. 21. Setting the Media Type● Accept Headers● Rails way - .:format
  22. 22. Representational based Models != Representations
  23. 23. Uniform Interface
  24. 24. Uniform Interface● Identification of resources● Manipulation of resources via representations● Self descriptive messages● Hypermedia as the engine of application state
  25. 25. Identification of resources
  26. 26. Manipulation of resources via representations
  27. 27. Self descriptive messages Statelessness
  28. 28. Hypermedia as the engine of application state HATEOAS
  29. 29. Clients should not know how to build routes
  30. 30. Enter HALJSON cannot describe a link
  31. 31. HAL is a media type fordefining links in JSON application/hal+json
  32. 32. The Goal GET /
  33. 33. Great, now I know what a Hypermedia API is.
  34. 34. How do I make one?
  35. 35. Rails + Lots of Gems Also monkey patching
  36. 36. Gems● ActiveModel::Serializer● RspecApiDocumentation● Raddocs● A few other handy ones
  37. 37. $ rails new hypermedia_api --skip-test-unit
  38. 38. $ vim Gemfilegem raddocsgem active_model_serializers
  39. 39. $ vim Gemfilegroup :test, :development do gem rspec-rails gem rspec_api_documentationend
  40. 40. Get rspec set up
  41. 41. Create our firstacceptance test
  42. 42. Generate models, index action, serializers
  43. 43. Show
  44. 44. Create
  45. 45. Update
  46. 46. Delete
  47. 47. Setup HALLet the monkey patching begin
  48. 48. Were missingsomething...
  49. 49. $ curl http://localhost:3000/ ""
  50. 50. Root Resource
  51. 51. Questions? Eric Oestrich @ericoestrich oestri.chsmartlogicsolutions.com

×