If you aren’t familiar with the term DSL, it stands for Domain Specific Language. It is a programming language with a higher level of abstraction optimized for a specific class of problems.

A DSL uses the concepts and rules from the field or domain. For example, Ruby on Rails provides a DSL for building web applications.

Rack provides such a DSL consisting of the following methods:

Additionally, the Rack::Builder class helps you with iteratively composing Rack applications.

For example, here's an example config.ru file using the above DSL:

# config.ru

require_relative './app'

app = Rack::Builder.new do
  use Rack::ShowExceptions
  use Rack::Logger

  map "/welcome" do
    use Rack::Lint
    run App.new
  end
end

run app

This DSL tells Rack to use the Rack::ShowExceptions and Rack::Logger middleware before using our App.

When a request comes from the web server, Rack will first use the exception-handling middleware, then the logging middleware, and finally run the app.

The app will process the incoming request, and return the response, which will again be examined and processed by the middleware stack, this time in the reverse sequence.