Wynn Netherland changelog.com/posts

Sinatra 1.3 is out!

Sinatra 1.3.0 is out with two big news items. The Chairman is now traveling with his own band. Sinatra Contrib, the community-sourced collection of extensions, is now versioned with Sinatra itself, ensuring compatibility. Sinatra Contrib provides some niceties on top of Sinatra for common tasks like config files, content_for, respond_with and other things you might miss from Rails.

Perhaps the bigger news is that Sinatra gigs can be streamed. No matter if you run evented servers like Thin, Rainbows! or Ebb or sequential servers like Unicorn, Passenger, or Mongrel, you have a single API:

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"
 end
end

Of course, you’ll need an evented server to keep connections open to things like:

set :server, :thin
connections = []

get '/' do
 # keep stream open
 stream(:keep_open) { |out| connections << out }
end

post '/' do
 # write to all open streams
 connections.each { |out| out << params[:message] << "n" }
 "message sent"
end

Smaller but just as cool changes include:

  • request.accept? for Accept headers
  • informal?, success?, redirect? and client_error? based on HTTP status code.
  • Support for If-Unmodified-Since header

Check out the official announcement or the changelog for a complete list of updates. Congrats to Konstantin Haase and the other contributors who made this happen.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00