Lightweight Webservices with Sinatra and RestClient

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

26 Favorites

Lightweight Webservices with Sinatra and RestClient - Presentation Transcript

  1. Lightweight web services with Sinatra and RestClient Adam Wiggins & Blake Mizerany Rubyconf 2008
  2. What for?
  3. app lifecycle
  4. Birth: small and beautiful
  5. Fate: sprawling mess
  6. web services
  7. Rails?
  8. Rails? Too much.
  9. Bare mongrel handler or Rack app?
  10. Bare mongrel handler or Rack app? Too little.
  11. Sinatra - the classy microframework for Ruby
  12. require 'rubygems' require 'sinatra' get '/' do \"Hello, whirled\" end
  13. $ ruby hello.rb
  14. require 'rubygems' require 'sinatra' require 'lib/posts' post '/posts' post = Post.create! params redirect \"/posts/#{post.id}\" do get '/posts/:id' do @post = Post.find(params[:id]) erb :post end
  15. ‣Templating (erb, haml, builder) ‣Tests/specs (test/spec, rspec, test::unit) ‣Before filters ‣Helpers ‣Error handlers ‣Inline templates ‣Code reloading ‣HTTP caching (etag, last-modified) ‣Rack / inline middleware
  16. A commitment to small
  17. A commitment to small Rails 87,990 Merb-core 12,417 Ramaze 11,796 Camping 1,704 Sinatra 1,576
  18. Sinatra is a proud Ruby citizen
  19. examples
  20. git-wiki http://github.com/sr/git-wiki 355 lines of Ruby
  21. get '/:page' do @page = Page.find(params[:page]) haml :show end __END__ @@ layout %html %body %content=yield @@ show %h1= title #page_content= @page.to_html
  22. rifgraf http://github.com/adamwiggins/rifgraf 61 lines of Ruby
  23. github-services http://github.com/pjhyett/github-services 423 lines of Ruby
  24. scanty http://github.com/adamwiggins/scanty 194 lines of Ruby
  25. client side
  26. ActiveResource?
  27. ActiveResource? Too much.
  28. Net::HTTP?
  29. Net::HTTP? Too little.
  30. RestClient - the Sinatra-inspired microclient for Ruby
  31. require 'rubygems' require 'rest_client' RestClient.get 'http://localhost:4567/posts'
  32. require 'rubygems' require 'rest_client' RestClient.post 'http://localhost:4567/posts', :author => 'Me', :title => 'First Post'
  33. Console $ restclient http://example.com >> post '/resource', :value => 42 => \"result\"
  34. A better curl $ restclient get http://example.com/posts > posts.xml $ restclient post http://example.com/posts < post.xml $ restclient put http://example.com/posts/1 < post.xml $ restclient delete http://example.com/posts/1
  35. Logging & replay $ RESTCLIENT_LOG=stdout ruby myscript.rb RestClient.get \"http://example.com/posts\" # => 200 OK | text/html 3781 bytes RestClient.post \"http://example.com/posts\", \"title=First+post\" # => 200 OK | text/html 40 bytes
  36. examples
  37. heroku-client http://github.com/adamwiggins/heroku-client
  38. couchrest http://github.com/jchris/couchrest
  39. principles
  40. “lagom”
  41. “lagom” just the right amount
  42. Fewer classes, less inheritance
  43. Controller object mapping & routes vs. URLs
  44. Controller object s ! RL mapping & routes U e r th fea vs. n ’t o URLs D
  45. Exposed simplicity instead of hidden complexity
  46. Small things, loosely joined, written fast - Justin Gehtland @ Relevance
  47. http://github.com/bmizerany/sinatra http://rest-client.heroku.com/ http://adam.blog.heroku.com/ Adam Wiggins & Blake Mizerany Rubyconf 2008

+ Adam WigginsAdam Wiggins, 2 years ago

custom

7887 views, 26 favs, 10 embeds more stats

Talk presented by Adam Wiggins & Blake Mizerany at more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 7887
    • 7475 on SlideShare
    • 412 from embeds
  • Comments 1
  • Favorites 26
  • Downloads 164
Most viewed embeds
  • 385 views on http://adam.blog.heroku.com
  • 12 views on http://desiremesh.com
  • 4 views on http://ranchero.com
  • 3 views on http://adamblog.heroku.com
  • 3 views on http://static.slideshare.net

more

All embeds
  • 385 views on http://adam.blog.heroku.com
  • 12 views on http://desiremesh.com
  • 4 views on http://ranchero.com
  • 3 views on http://adamblog.heroku.com
  • 3 views on http://static.slideshare.net
  • 1 views on http://lj-toys.com
  • 1 views on http://74.125.47.132
  • 1 views on http://scanty-redis.heroku.com
  • 1 views on http://74.125.155.132
  • 1 views on http://rubyglass.heroku.com

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories