Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building with Rack
Search
Alexander Clark
February 23, 2016
Programming
370
2
Share
Building with Rack
Let's build a Rack app!
Alexander Clark
February 23, 2016
More Decks by Alexander Clark
See All by Alexander Clark
Off the Rails: Patterns for fixing fat models, out-of-controllers, and other Rails problems
alexanderclark
0
360
Docker: What It Is and Why You Should Care
alexanderclark
0
380
Other Decks in Programming
See All in Programming
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
180
AIとRubyの静的型付け
ukin0k0
0
460
Oxcを導入して開発体験が向上した話
yug1224
4
260
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
ECR拡張スキャンでSBOMを収集して サプライチェーン攻撃の影響調査を 爆速で終わらせてみた
akihisaikeda
2
210
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
130
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
230
OSもどきOS
arkw
0
330
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
2k
iOS26時代の新規アプリ開発
yuukiw00w
0
220
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
2
370
Inside Stream API
skrb
1
400
Featured
See All Featured
Tell your own story through comics
letsgokoyo
1
930
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Un-Boring Meetings
codingconduct
0
300
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Ruling the World: When Life Gets Gamed
codingconduct
0
240
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
310
Transcript
Building with Rack Alexander Clark
What is Rack?
?
None
?
None
?
?
What does a Rack app look like? ?
What does a Rack app look like? GET /foo HTTP/1.1
Host: localhost:9292 Accept: text/html … ?
What does a Rack app look like? GET /foo HTTP/1.1
Host: localhost:9292 Accept: text/html … ? <!DOCTYPE html> <html> <head> …
run Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']]
}
run Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']]
} Responds to #call HTTP Status code Headers Response body Run
run Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']]
} Responds to #call Much HTTP Status code Such Headers Response body Wow Run
Let’s build something!
None
<!DOCTYPE html> <html> <head> <title>Is it April Fools?</title> </head> <body>
<h1><%= @april_fools ? 'YES' : 'NO' %></h1> </body> </html>
require 'erb' class MyRackApp def initialize @april_fools = Time.now.strftime('%m%d') ==
'0401' end def call(_env) ['200', {'Content-Type' => 'text/html'}, view] end def view [ERB.new(template).result(binding)] end def template File.open('index.html.erb', 'r').read end end
require './my_rack_app' run MyRackApp.new
None
?
run Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']]
} run MyRackApp.new ... def call(_env) ['200', {'Content-Type' => 'text/html'}, view] end
run MyRackApp.new run Rails.application
Middleware
TL;DL
Further Reading • https://rack.github.io/ • http://alexander-clark.com/blog/building-a-rack-app/ • http://www.justinweiss.com/articles/a-web-server-vs- an-app-server/ •
https://www.amberbit.com/blog/2011/07/13/ introduction-to-rack-middleware/
Thanks for Listening Alexander Clark atheclark alexander-clark.com alexander-clark