A Practical Guide To Hypermedia APIs - Philly.rb

1,667 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
1,667
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A Practical Guide To Hypermedia APIs - Philly.rb

  1. 1. A Practical Guide to Hypermedia APIsEric OestrichPhilly.rb2013-03-12
  2. 2. Eric Oestrich SmartLogic Solutionshttp://www.smartlogicsolutions.com@ericoestrichgithub.com/oestrich
  3. 3. A Brief Intro to the Domain
  4. 4. NerdWord github.com/smartlogic/nerdword github.com/smartlogic/nerdword-apigithub.com/smartlogic/nerdword-client-ruby
  5. 5. Definitely Not Scrabble
  6. 6. Resources
  7. 7. Users Actions: RegisterBasic Auth
  8. 8. GamesUsers that are playing on a shared board Actions: Create List View Play Move
  9. 9. MoveSet of tiles to be played at a location
  10. 10. TurnsActions: List View
  11. 11. See It In Actionhttps://github.com/smartlogic/nerdword-api/ blob/master/script/client.rb
  12. 12. Hypermedia Basics
  13. 13. Client Knows Only One URL "/"
  14. 14. Media Types HAL
  15. 15. Example HAL{ "status": "Processing", "_embedded": { "items": [ { "name": "Book", "_links":{ "self": { "href" => "http://example.com/items/1" }} } ] }, "_links": { "self" => { "href" => "http://example.com/orders/1" } }}
  16. 16. Server Side
  17. 17. Controllers Rails::Api
  18. 18. ModelsDo not have to be ActiveRecord::Base
  19. 19. ResourcesShould not be all of your models exported
  20. 20. Serializers Disable root Links Embedded resourcesChanging serializer representations
  21. 21. Client Side
  22. 22. Basics Faraday Basic auth over SSLHandle link traversal
  23. 23. Resources Data onlyConvenience methods Links
  24. 24. LoadersPull down data Only GETs
  25. 25. ServicesVery similar to Loaders Push data back up Perform actions POST, PUT
  26. 26. Helpful Resources● Creating a Hypermedia Client ○ http://blog.oestrich.org/2012/12/creating-a-hypermedia- client/● ActiveModel::Serializers ○ https://github.com/rails-api/active_model_serializers● Abusing ActiveModel::Serializers for HAL ○ http://blog.oestrich.org/2012/10/abusing-active-model- serializers-for-hal/● httpstatus.es
  27. 27. Useful Gems for APIs rspec_api_documentation raddocs letter json_spec vcr webmock cane
  28. 28. Questions?http://www.smartlogicsolutions.comhttp://www.twitter.com/smartlogichttp://www.github.com/smartlogic http://www.facebook.com/smartlogic

×