Skip to content

Instantly share code, notes, and snippets.

@dwayne
Last active December 11, 2015 23:09
Show Gist options
  • Save dwayne/4674948 to your computer and use it in GitHub Desktop.
Save dwayne/4674948 to your computer and use it in GitHub Desktop.
Notes on Rack
# Tell Rack to run this application using `rackup hello.ru`
app = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello, world!']] }
run app
# What is `rackup`?
# `rackup` is an executable that takes the code, finds a web server for it and then runs it.
# See https://github.com/rack/rack/blob/f65969ccac8f6098acee9b1ab506283dfcdf18a5/bin/rackup.

What is Rack?

Rack aims to provide a minimal API for connecting web servers supporting Ruby (like WEBrick, Mongrel etc.) and Ruby web frameworks (like Rails, Sinatra etc.).

A Rack application is a Ruby object (not a class) that responds to call. It takes exactly one argument, the environment and returns an Array of exactly three values: The status, the headers, and the body.

Rack Apps

Rack Middleware

The fundamental idea behind Rack middleware is - come between the calling client and the server, process the HTTP request before sending it to the server, and processing the HTTP response before returning it to the client.

What's the difference between Rack Middleware and Rack Application

Read. Unlike Rack applications, Rack middleware has knowledge of other Rack applications.

Books

Videos

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment