A Practical Guide to Hypermedia APIs

1,916 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,916
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A Practical Guide to Hypermedia APIs

  1. 1. A Practical Guide to Hypermedia APIs Eric Oestrich @ericoestrich @smartlogicsolutions
  2. 2. woofound.com
  3. 3. That was this project Prepare yourself
  4. 4. Please note that this has been heavily stripped down Dont want to give everything away
  5. 5. But firstHypermedia Basics
  6. 6. Resources != Models
  7. 7. HTTP is your friend methods and status codes
  8. 8. Client knows only one URL "/"
  9. 9. Media types HAL
  10. 10. Sample HAL Response{ "status": "Processing", "_embedded": { "items": [ { "name": "Book", "_links":{ "self": { "href" => "http://example.com/items/1" } } } ] }, "_links": { "self" => { "href" => "http://example.com/orders/1" } }}
  11. 11. Server
  12. 12. Controllers● Use respond_to and respond_with
  13. 13. Models● Doesnt have to be a subclass of ActiveRecord::Base
  14. 14. Serializers● Disable root● Links● Embedded resources● Changing serializer representations
  15. 15. Client
  16. 16. Basics● Uses Faraday● Basic auth over SSL
  17. 17. Resources● Data only● Convenience methods● Links
  18. 18. Loaders● Pull data down from the API● Only GETs
  19. 19. Services● Very similar to Loaders● Push data back up
  20. 20. Integrating with Rails
  21. 21. Problems● There are no ids● Speed
  22. 22. 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
  23. 23. Useful gems for apis● rspec_api_documentation● raddocs● letter● json_spec● vcr● webmock● cane
  24. 24. Hobostove Campfire for the command linehttps://github.com/oestrich/hobostove

×