This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chris Schneider <chris@christopher-schneider.com>
- Loading branch information
Showing
22 changed files
with
25 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,8 +1,30 @@ | |||
Rack Middleware | Rack Middleware | ||
=============== | =============== | ||
|
|
||
"use" | Sinatra rides on [Rack][rack], 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. | ||
----- | |||
|
|
||
// TODO: What useful rack middleware is out there? Is there any 3rd party stuff available outside of the builtin ones? | Sinatra makes building Rack middleware pipelines a cinch via a top-level "use" method: | ||
|
|||
require 'sinatra' | |||
require 'my_custom_middleware' | |||
|
|||
use Rack::Lint | |||
use MyCustomMiddleware | |||
|
|||
get '/hello' do | |||
'Hello World' | |||
end | |||
|
|||
|
|||
The semantics of "use" are identical to those defined for the [Rack::Builder][rack_builder] DSL (most frequently used from rackup files). For example, the use method accepts multiple/variable args as well as blocks: | |||
|
|||
use Rack::Auth::Basic do |username, password| | |||
username == 'admin' && password == 'secret' | |||
end | |||
|
|||
|
|||
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. | |||
|
|||
[rack]: http://rack.rubyforge.org/ | |||
[rack_builder]: http://rack.rubyforge.org/doc/classes/Rack/Builder.html | |||
|
|
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.