Last active
December 29, 2015 21:19
-
-
Save jay16/7729505 to your computer and use it in GitHub Desktop.
refer to: http://rack.rubyforge.org/doc/
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
Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call. | |
The exact details of this are described in the Rack specification, which all Rack applications should conform to. | |
## Supported web servers | |
The included handlers connect all kinds of web servers to Rack: | |
1. Mongrel | |
2. EventedMongrel | |
3. SwiftipliedMongrel | |
4. WEBrick | |
5. FCGI | |
6. CGI | |
7. SCGI | |
8. LiteSpeed | |
9. Thin | |
~~~~ ruby | |
irb(main):001:0> require 'rack' | |
=> true | |
irb(main):002:0> Rack::Handler.constants | |
=> [:CGI, :FastCGI, :Mongrel, :EventedMongrel, :SwiftipliedMongrel, :WEBrick, :LSWS, :SCGI, :Thin] | |
~~~~ | |
These web servers include Rack handlers in their distributions: | |
1. Ebb | |
2. Fuzed | |
3. Glassfish v3 | |
4. Phusion Passenger (which is mod_rack for Apache and for nginx) | |
5. Puma | |
6. Rainbows! | |
7. Reel | |
8. Unicorn | |
9. unixrack | |
10. uWSGI | |
11. Zbatery | |
Any valid Rack app will run the same on all these handlers, without changing anything. | |
## Supported web frameworks | |
These frameworks include Rack adapters in their distributions: | |
1. Camping | |
2. Coset | |
3. Espresso | |
4. Halcyon | |
5. Mack | |
6. Maveric | |
7. Merb | |
8. Racktools::SimpleApplication | |
9. Ramaze | |
10. Ruby on Rails | |
11. Rum | |
12. Sinatra | |
13. Sin | |
14. Vintage | |
15. Waves | |
16. Wee | |
and many others. | |
## Available middleware | |
Between the server and the framework, Rack can be customized to your applications needs using middleware, for example: | |
1. Rack::URLMap, to route to multiple applications inside the same process. | |
2. Rack::CommonLogger, for creating Apache-style logfiles. | |
3. Rack::ShowException, for catching unhandled exceptions and presenting them in a nice and helpful way with clickable backtrace. | |
4. Rack::File, for serving static files. | |
All these components use the same interface, which is described in detail in the Rack specification. These optional components can be used in any way you wish. | |
Convenience | |
If you want to develop outside of existing frameworks, implement your own ones, or develop middleware, Rack provides many helpers to create Rack applications quickly and without doing the same web stuff all over: | |
1. Rack::Request, which also provides query string parsing and multipart handling. | |
2. Rack::Response, for convenient generation of HTTP replies and cookie handling. | |
3. Rack::MockRequest and Rack::MockResponse for efficient and quick testing of Rack application without real HTTP round-trips. | |
## rack-contrib | |
The plethora of useful middleware created the need for a project that collects fresh Rack middleware. rack-contrib includes a variety of add-on components for Rack and it is easy to contribute new modules. | |
+ github.com/rack/rack-contrib | |
## rackup | |
rackup is a useful tool for running Rack applications, which uses the Rack::Builder DSL to configure middleware and build up applications easily. | |
rackup automatically figures out the environment it is run in, and runs your application as FastCGI, CGI, or standalone with Mongrel or WEBrick—all from the same configuration. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment