GOAL: To create a Rack-compliant web application that can talk to Puma application server.

Create the following Ruby script called app.rb in the weby directory. This is our application.

Yes, IT IS our entire app.

# weby/app.rb

class App
  def call(env)

    # a hash containing response headers
    headers = {
      "Content-Type" => "text/html"
    }

    # an array containing the HTML response string
    response = ["<h1>Hello World!</h1>"]

    # an array containing
    # 1. HTTP status code
    # 2. HTTP headers 
    # 3. HTTP response
    [200, headers, response]
  end
end

The above script is a complete Rack-compliant web application. As you can see, it follows the Rack protocol.

  1. It has a call method that takes an env object.
  2. It returns an array containing the status, headers, and response.

Now let's see how we can make the Puma app server talk to our application using the Rack protocol.