Lightweight Webservices with Sinatra and RestClient
Upcoming SlideShare
Loading in...5
×
 

Lightweight Webservices with Sinatra and RestClient

on

  • 43,064 views

Talk presented by Adam Wiggins & Blake Mizerany at Rubyconf 2008

Talk presented by Adam Wiggins & Blake Mizerany at Rubyconf 2008

Statistics

Views

Total Views
43,064
Views on SlideShare
40,926
Embed Views
2,138

Actions

Likes
62
Downloads
486
Comments
2

25 Embeds 2,138

http://blog.assimov.net 903
http://adam.heroku.com 394
http://adam.blog.heroku.com 392
http://www.slideshare.net 218
http://localhost:4000 77
http://adam.herokuapp.com 49
http://scanty-redis.heroku.com 31
http://cloudlines.tumblr.com 18
http://adamblog.heroku.com 15
http://desiremesh.com 12
http://webcache.googleusercontent.com 5
http://ranchero.com 4
http://www.slideee.com 3
http://www.e-presentations.us 3
http://static.slideshare.net 3
https://twitter.com 2
http://zootool.com 1
http://a0.twimg.com 1
http://74.125.47.132 1
http://74.125.155.132 1
https://si0.twimg.com 1
http://localhost 1
http://www.yatedo.fr 1
http://lj-toys.com 1
http://rubyglass.heroku.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Nice presentation on Sinatra
    Are you sure you want to
    Your message goes here
    Processing…
  • This is great, but the video is even better http://rubyconf2008.confreaks.com/lightweight-web-services.html
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Lightweight Webservices with Sinatra and RestClient Lightweight Webservices with Sinatra and RestClient Presentation Transcript

  • Lightweight web services with Sinatra and RestClient Adam Wiggins & Blake Mizerany Rubyconf 2008
  • What for?
  • app lifecycle
  • Birth: small and beautiful
  • Fate: sprawling mess
  • web services
  • Rails?
  • Rails? Too much.
  • Bare mongrel handler or Rack app?
  • Bare mongrel handler or Rack app? Too little.
  • Sinatra - the classy microframework for Ruby
  • require 'rubygems' require 'sinatra' get '/' do quot;Hello, whirledquot; end
  • $ ruby hello.rb
  • require 'rubygems' require 'sinatra' require 'lib/posts' post '/posts' post = Post.create! params redirect quot;/posts/#{post.id}quot; do get '/posts/:id' do @post = Post.find(params[:id]) erb :post end
  • ‣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
  • A commitment to small
  • A commitment to small Rails 87,990 Merb-core 12,417 Ramaze 11,796 Camping 1,704 Sinatra 1,576
  • Sinatra is a proud Ruby citizen
  • examples
  • git-wiki http://github.com/sr/git-wiki 355 lines of Ruby
  • 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
  • rifgraf http://github.com/adamwiggins/rifgraf 61 lines of Ruby
  • github-services http://github.com/pjhyett/github-services 423 lines of Ruby
  • scanty http://github.com/adamwiggins/scanty 194 lines of Ruby
  • client side
  • ActiveResource?
  • ActiveResource? Too much.
  • Net::HTTP?
  • Net::HTTP? Too little.
  • RestClient - the Sinatra-inspired microclient for Ruby
  • require 'rubygems' require 'rest_client' RestClient.get 'http://localhost:4567/posts'
  • require 'rubygems' require 'rest_client' RestClient.post 'http://localhost:4567/posts', :author => 'Me', :title => 'First Post'
  • Console $ restclient http://example.com >> post '/resource', :value => 42 => quot;resultquot;
  • 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
  • Logging & replay $ RESTCLIENT_LOG=stdout ruby myscript.rb RestClient.get quot;http://example.com/postsquot; # => 200 OK | text/html 3781 bytes RestClient.post quot;http://example.com/postsquot;, quot;title=First+postquot; # => 200 OK | text/html 40 bytes
  • examples
  • heroku-client http://github.com/adamwiggins/heroku-client
  • couchrest http://github.com/jchris/couchrest
  • principles
  • “lagom”
  • “lagom” just the right amount
  • Fewer classes, less inheritance
  • Controller object mapping & routes vs. URLs
  • Controller object s ! RL mapping & routes U e r th fea vs. n ’t o URLs D
  • Exposed simplicity instead of hidden complexity
  • Small things, loosely joined, written fast - Justin Gehtland @ Relevance
  • http://github.com/bmizerany/sinatra http://rest-client.heroku.com/ http://adam.blog.heroku.com/ Adam Wiggins & Blake Mizerany Rubyconf 2008