public
Fork of bmizerany/sinatra
Description: Classy web-development dressed in a DSL
Homepage: http://sinatrarb.com
Clone URL: git://github.com/cypher/sinatra.git
add doc on using Rack middleware to README
rtomayko (author)
Mon May 19 14:25:09 -0700 2008
commit  a766406d168db2714f7ab7b0bf7adaf7043943ff
tree    290d38f55c12ff20116c79b7dcd751a7462666f3
parent  d2cfe06c3b177a351f5f16d186620ab2995759c9
...
349
350
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
353
354
...
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
0
@@ -349,6 +349,30 @@ When using send_file or static files you may have mime types Sinatra doesn't und
0
 
0
   mime :foo, 'text/foo'
0
 
0
+= Using Rack Middleware
0
+
0
+Sinatra rides on Rack[http://rack.rubyforge.org/], a minimal standard interface for Ruby web frameworks. One of Rack's most interesting capabilities for application developers is support for "middleware" -- components that sit between the server and your application monitoring and/or manipulating the HTTP request/response to provide various types of common functionality. What's more, middleware is portable between web frameworks, so middleware components developed under, e.g., Merb, can be used with Sinatra and vice versa.
0
+
0
+Sinatra makes building Rack middleware pipelines a cinch via a top-level +use+ method:
0
+
0
+ require 'sinatra'
0
+ require 'my_custom_middleware'
0
+
0
+ use Rack::Lint
0
+ use MyCustomMiddleware
0
+
0
+ get '/hello' do
0
+ 'Hello World'
0
+ end
0
+
0
+The semantics of +use+ are identical to those defined for the Rack::Builder[http://rack.rubyforge.org/doc/classes/Rack/Builder.html] DSL (most frequently used from rackup files). For example, the +use+ method accepts multiple/variable args as well as blocks:
0
+
0
+ use Rack::Auth::Basic do |username, password|
0
+ username == 'admin' && password == 'secret'
0
+ end
0
+
0
+Rack is distributed with a variety of standard middleware for logging, debugging, URL routing, authentication, and session handling. Sinatra uses many of of these components automatically based on configuration so you typically don't have to +use+ them explicitly.
0
+
0
 = Testing
0
 
0
 === Methods

Comments

    No one has commented yet.