SinatraPast, Present and Future
Konstantin Haase
Hi!
I'm Konstantin.
I write code.
Back in the internet, I'm aka'ed as
@konstantinhaase on Titter
rkh on GitHub
khaase on IRC
rkh.im on DNS
"The big lesson in life, baby, is neverbe scared of anyone or anything."
Frank Sinatra
"Outlines are great, quotes areterrible."
Ben Orenstein (Speaking For Hackers)
Outline
The Past
The Present
The Future
Let's pretend you don'tknow a thing...
... about Sinatra
... about Rails
... about Rack
The PastOr: "How We Do HTTP"
1993
CGI
#!/usr/bin/env perlprint "Content-type: text/html\n";if ($ENV{"REQUEST_METHOD"} != "HEAD") { print "\n<h1>Hello Perl!</h1>\n"}
No structure (Hello, inline SQL!)
Enormous performance overhead
No asynchronous/streaming API
Perl? Seriously?
December 21, 1995
Ruby 0.95
#!/usr/bin/env rubyputs "Content-Type: text/html"if ENV["REQUEST_METHOD"] != "HEAD" puts "", "<h1>Hello Ruby!</h1>"end
Servlets
require 'webrick'class Simple < WEBrick::HTTPServlet def do_GET(req, res) res.status = 200 res['Content-Type'] = "text/html" res.body = "<h1>Hello Ruby!</h1>" endend
Not web server independent
No asynchronous/streaming API
Limited eco system
July 2004
Ruby On Rails
Oh
My
God!
Convention Over Configuration�
Do Not Repeat Yourself
Model - View - Controler
Testing
The eco system, oh my!
Did not play well with others
Framework, not a library
No asynchronous/streaming API
Summer 2005
I discover Ruby!Woohoo!
December 13, 2005
Rails 1.0
March 2007
Rack 0.1
proc do |env| [200, {"Content-Type" => "text/html"}, ["<h1>Hello Ruby!</h1>"]]end
The simplest thing possible
Zero dependency applications
Great middleware/router infrastrucutre
Server independent applications
Easy testing
Near unusable directly
Rails didn't use it
No asynchronous/streaming API
September 9, 2007
Sinatra 0.0.1
get('/') { body "Hello World!" }post('/') { erb :posted }
Simple and clean DSL for writing Rackapplication.
Library, not framework
Plays well with anything Rack
No hidden magic
Pollutes Object
Uses instance_eval (slow)
No asynchronous/streaming API
One application per process
October 7, 2007
Sinatra 0.1.0
October 8, 2007
Sinatra 0.1.5
before { puts "starting" }get('/') { "Hello World!" }delete('/') { haml :deleted }after { puts "done" }
November 21, 2007
rm -Rf sinatra
April 12, 2008
Sinatra 0.2.0(Complete Rewrite)
before { halt 404 if path !~ /css/ }error(404) { "page not found" }get '/:name.css', :agent => /Firefox/ do sass :firefoxend
April 14, 2008
rm -Rf sinatra
September 8, 2008
Sinatra 0.3.0
use Rack::Lintconfigure { enable :lock }get('/*.css') { sass :style }__END__@@ stylebody color: red
# config.ruuse SomeMiddlewaremap('/a') { run Sinatra::Application }map('/b') { run Merb::Application }
December 13, 2008
rm -Rf sinatra
January 18, 2009
Sinatra 0.9.0
class MyApp < Sinatra::Base get /js(on)?/, :provides => "json" do pass unless params[:pwd] == "foo" "Hello World".to_json end get "*" do "wrong password, probably" endend
No more instance_eval for routes
More than one application per process
March 23, 2010
Sinatra 1.0Major Refactorings since 0.9.0
Tilt has been extracted
A ton of new helper methods
Semantic Versioning
April - September 2010
Maintainance crisis
October 24, 2010
1.1.0
before agent: /Firefox/ do headers['X-Is-Firefox'] = "yes"endget('/') { markdown "# Hello World!" }
March 3, 2011
1.2.0Major Refactoring
Live release at Ruby Use Group Berlin
Better extension API
Better security
Long term support
September 30, 2011
1.3.0
Live release at RubyConf in New Orleans
Better HTTP compatibility
Better security (rack-protection)
Stream/asynchronous API, finally!�
get '/' do stream do |out| out << "It's gonna be legen -\n" sleep 0.5 out << " (wait for it) \n" sleep 1 out << "- dary!\n" endend
connections = []get '/' do stream(:keep_open) do |out| connections << out endendpost '/' do connections.each do |out| out << params[:message] end "message sent"end
The Present
Who's using it?
Travis CI, Integrity, CI Joe
Picky, Resque, Gollum
Heroku, Github, Engine Yard
Songbird, University of Lausanne, Stanford
Apple, LinkedIn, British Government, BBC
...
It inspired a lot of otherprojects!
Ruby: Almost Sinatra, Astaire, Cuba, Padrino (based on Sinatra), Pakyow,Renee PHP: Fat-Free, Fitzgerald, Glue, klein, Laravel, Limonade,
MiMViC, Silex, Slim JavaScript: Express, Picard, Roundabout, SammyCoffeeScript: Zappa Python: Bottle, Denied, Flask, itty, Juno Erlang:
Fresh, Spooky Groovy: Graffiti, Ratpack �Scala: Scalatra, BlueEyes.NET: Martin, Nancy, Nina Perl: Dancer, Mojolicious Java: Spark,
Napalm, Htmleasy Haskell: Bird, Loli Fancy: Sinatra.fy Bash: Astley,sh.inatra C: Bogart F#: Frank Lua: Mercury, Orbit Mirah: Shatner
Objective-C: RCRouter Vala: Valatra Smalltalk: RatPack
That's 52 projects in 20 languages.
The Future
2012
Sinatra 1.4.0
No longer pollute Object
# Sinatra since 0.9.0include Sinatra::Delegator10.send(:get, '/') do "this works, but it shouldn't"end
def foo 42endfoo # => 42"hi there".foo # => 42
self # => maindef self.foo 42endfoo # => 42"hi there".foo # NoMethodError
class << self include Sinatra::Delegatorend10.send(:get, '/') do "Now this raises a NoMethodError"end
extend Sinatra::Delegator10.send(:get, '/') do "Now this raises a NoMethodError"end
some day
Sinatra 2.0
Use successor of Rack (code name Ponies)
rm -Rf sinatra?
Thanks!github.com / rkh / presentations
Top Related