35. Data Format (JSON & XML)
Always Use Object Notation
Rails has #to_json and #to_xml
Define #as_json for obj primitive.
Monday, September 12, 11
36. Data Format (JSON & XML)
Always Use Object Notation
Rails has #to_json and #to_xml
Define #as_json for obj primitive.
New objects using #from_json and
#from_xml methods.
Monday, September 12, 11
38. Representation
State Transfer
(REST)
Monday, September 12, 11
39. Representation
State Transfer
(REST)
CREATE READ UPDATE DELETE
DB INSERT SELECT UPDATE DELETE
HTTP POST GET PUT DELETE
Monday, September 12, 11
40. Representation
State Transfer
(REST)
CREATE READ UPDATE DELETE
DB INSERT SELECT UPDATE DELETE
HTTP POST GET PUT DELETE
Monday, September 12, 11
41. Representation
State Transfer
(REST)
CREATE READ UPDATE DELETE
DB INSERT SELECT UPDATE DELETE
HTTP POST GET PUT DELETE
Monday, September 12, 11
42. Representation
State Transfer
(REST)
GET /users {:controller=>"users", :action=>"index"}
POST /users {:controller=>"users", :action=>"create"}
GET /users/:id {:controller=>"users", :action=>"show"}
PUT /users/:id {:controller=>"users", :action=>"update"}
DELETE /users/:id {:controller=>"users", :action=>"destroy"}
Monday, September 12, 11
46. HTTP Clients In Ruby
Many choices!
Ruby’s core lib Net::HTTP looks more
like wizardry vs idiomatic Ruby.
Monday, September 12, 11
47. HTTP Clients In Ruby
Many choices!
Ruby’s core lib Net::HTTP looks more
like wizardry vs idiomatic Ruby.
Research and pick one that works
best for you.
Monday, September 12, 11
48. HTTP Clients In Ruby
http://ruby-toolbox.com/categories/http_clients.html
Monday, September 12, 11
49. Typhoeus
High Speed!
Built On Top Of libcurl
Simple RESTful Request
Parallel Requests
Memoization & Caching
https://github.com/dbalatero/typhoeus
Monday, September 12, 11
50. Typhoeus
hydra = Typhoeus::Hydra.new
request = Typhoeus::Request.new("http://localhost/posts/1.json")
request.on_complete do |response|
json = JSON.parse(response.body)
post = Post.new.from_json(json)
# Do crazy callback stuff...
end
hydra.queue request
hydra.run # This is a blocking call that
# returns once all requests are complete.
Monday, September 12, 11