Successfully reported this slideshow.
Your SlideShare is downloading. ×

REST with Her (and let Her take care of the REST)

Ad

@happynoff
AndletHertakecareoftheREST
RESTwithHer
bySimonCourtois

Ad

@happynoff
Rails+RESTAPI

Ad

@happynoff
ActiveResource?

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Upcoming SlideShare
Contributing to Impala
Contributing to Impala
Loading in …3
×

Check these out next

1 of 34 Ad
1 of 34 Ad
Advertisement

More Related Content

Advertisement

REST with Her (and let Her take care of the REST)

  1. 1. @happynoff AndletHertakecareoftheREST RESTwithHer bySimonCourtois
  2. 2. @happynoff Rails+RESTAPI
  3. 3. @happynoff ActiveResource?
  4. 4. @happynoff RemovedinRails4
  5. 5. @happynoff ActiveModel+Net::HTTP?
  6. 6. @happynoff Faraday?
  7. 7. @happynoff Her
  8. 8. @happynoff gem‘her’
  9. 9. @happynoff ontopofFaraday Middlewaresforfree!w00t!
  10. 10. @happynoff # config/initializers/her.rb Her::API.setup url: 'http://api.expl.com' do |co| co.use Faraday::Request::UrlEncoded co.use Her::Middleware::DefaultParseJSON co.use Faraday::Adapter::NetHttp end
  11. 11. @happynoff class User include Her::Model end
  12. 12. @happynoff User.all # GET https://api.expl.com/users # => [#<User ...>, #<User ...>, ...]
  13. 13. @happynoff User.find(1) # GET https://api.expl.com/users/1 # => #<User ...>
  14. 14. @happynoff User.create(login: “parisrb”) # POST https://api.expl.com/users # => #<User ...>
  15. 15. @happynoff user = User.create(login: “parisrb”) user.active = true user.save # POST https://api.expl.com/users # => #<User ...>
  16. 16. @happynoff user = User.find(1) user.active = true user.save # PUT https://api.expl.com/users/1 # => #<User ...>
  17. 17. @happynoff user = User.find(1) user.destroy # DELETE https://api.expl.com/users/1 # => #<User ...>
  18. 18. @happynoff ✔BasicCRUD
  19. 19. @happynoff User.where(moderator: 1).all # GET /users?moderator=1 # => [#<User ...>, ...]
  20. 20. @happynoff class User include Her::Model custom_get :popular end User.popular # GET /users/popular # => [#<User ...>, #<User ...>]
  21. 21. @happynoff class User include Her::Model collection_path ‘/published-users/:id’ end User.find(1) # GET /published-users/1 # => #<User ...>
  22. 22. @happynoff ✔Customfinders
  23. 23. @happynoff canIhazmanycomments?
  24. 24. @happynoff class User include Her::Model has_many :comments end class Comment include Her::Model end
  25. 25. @happynoff user = User.find(1) # GET /users/1 # { "id": 1, "login": "parisrb" } user.comments # GET /users/1/comments # => [#<Comment ...>, #<Comment ...>]
  26. 26. @happynoff user = User.find(1) # GET /users/1 # { # "id": 1, # "login": "parisrb", # “comments”: [ # { "id": 1, "text": "Foo" }, # { "id": 2, "text": "Bar" } # ] # } user.comments # => [#<Comment ...>, #<Comment ...>]
  27. 27. @happynoff ✔associations
  28. 28. @happynoff Middlewares!
  29. 29. @happynoff gem‘faraday_middleware’
  30. 30. @happynoff # config/initializers/her.rb Her::API.setup url: 'http://api.expl.com' do |co| co.use FaradayMiddleware::Caching, Memcached::Rails.new(...) # ... end
  31. 31. @happynoff customMiddlewares
  32. 32. @happynoff ✔awesomeness
  33. 33. @happynoff http://her-rb.org https://github.com/remiprev/her Her Faraday https://github.com/lostisland/faraday https://github.com/lostisland/faraday_middleware
  34. 34. @happynoff Thankyou!

×