Photo by Francesco Ungaro on Unsplash, Rack Lobster

Introduction

What is Rack?

The Rack RubyGem serves as an interface between the application and the application server during the request-response cycle.
Rack offers support for many servers, and many applications can be Rack-based.

What makes an application Rack-based?

A Rack app must define a method named call that takes one argument.
This constitutes a minimum viable Rack application
require 'rack'class MyApp
def call(env)
['200', { "Content-Type" => "text/plain" }, ["hello world"]]
end
end
Rack::Handler::WEBrick.run MyApp.new
require 'rack'class MyApp
def call(env)
body = "<h2>Hello in Style!</h2>"
['200', { "Content-Type" => "text/html" }, [body]]
end
end
Rack::Handler::WEBrick.run MyApp.new

What is env?

require 'rack'class MyApp
def call(env)
['200', { "Content-Type" => "text/plain" }, [env.to_s]]
end
end
Rack::Handler::WEBrick.run MyApp.new

Next level of abstraction, please

require 'rack'class MyApp
def call(env)
['200', { "Content-Type" => "text/plain" }, ["hello world"]]
end
end
Rack::Handler::WEBrick.run MyApp.new
Rack source code here

Part 1: Summary

Research analyst turned aspiring web developer. Learning the fundamentals with Launch School. Lives in Denver, CO.