Browse files

Add a note about Sinatra::Base to the README

Edited-By: Ryan Tomayko <>
  • Loading branch information...
sr authored and rtomayko committed Jun 6, 2009
1 parent e997abb commit 29e01ebc5b0a52ec8dcdf75ac7b3e3aec976a317
Showing with 50 additions and 0 deletions.
  1. +50 −0 README.rdoc
@@ -470,6 +470,56 @@ recommended:
NOTE: The built-in Sinatra::Test module and Sinatra::TestHarness class
are deprecated as of the 0.9.2 release.
+== Sinatra::Base - Middleware, Libraries, and Modular Apps
+Defining your app at the top-level works well for micro-apps but has
+considerable drawbacks when building reuseable components such as Rack
+middleware, Rails metal, simple libraries with a server component, or
+even Sinatra extensions. The top-level DSL pollutes the Object namespace
+and assumes a micro-app style configuration (e.g., a single application
+file, ./public and ./views directories, logging, exception detail page,
+etc.). That's where Sinatra::Base comes into play:
+ require 'sinatra/base'
+ class MyApp < Sinatra::Base
+ set :sessions, true
+ set :foo, 'bar'
+ get '/' do
+ 'Hello world!'
+ end
+ end
+The MyApp class is an independent Rack component that can act as
+Rack middleware, a Rack application, or Rails metal. You can +use+ or
++run+ this class from a rackup file; or, control a server
+component shipped as a library:
+! :host => 'localhost', :port => 9090
+The methods available to Sinatra::Base subclasses are exactly as those
+available via the top-level DSL. Most top-level apps can be converted to
+Sinatra::Base components with two modifications:
+* Your file should require +sinatra/base+ instead of +sinatra+;
+ otherwise, all of Sinatra's DSL methods are imported into the main
+ namespace.
+* Put your app's routes, error handlers, filters, and options in a subclass
+ of Sinatra::Base.
++Sinatra::Base+ is a blank slate. Most options are disabled by default,
+including the built-in server. See {Options and Configuration}[]
+for details on available options and their behavior.
+SIDEBAR: Sinatra's top-level DSL is implemented using a simple delegation
+system. The +Sinatra::Application+ class -- a special subclass of
+Sinatra::Base -- receives all :get, :put, :post, :delete, :before,
+:error, :not_found, :configure, and :set messages sent to the
+top-level. Have a look at the code for yourself: here's the
+{Sinatra::Delegator mixin}[]
+being {included into the main namespace}[].
== Command line
Sinatra applications can be run directly:

0 comments on commit 29e01eb

Please sign in to comment.