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
2
360
Building with Rack
Let's build a Rack app!
Alexander Clark
February 23, 2016
Tweet
Share
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
350
Docker: What It Is and Why You Should Care
alexanderclark
0
360
Other Decks in Programming
See All in Programming
あなたはユーザーではない #PdENight
kajitack
4
290
2026/02/04 AIキャラクター人格の実装論 口 調の模倣から、コンテキスト制御による 『思想』と『行動』の創発へ
sr2mg4
0
650
CDIの誤解しがちな仕様とその対処TIPS
futokiyo
0
140
AI主導でFastAPIのWebサービスを作るときに 人間が構造化すべき境界線
okajun35
0
420
TipKitTips
ktcryomm
0
130
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
220
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
790
CSC307 Lecture 11
javiergs
PRO
0
580
CSC307 Lecture 14
javiergs
PRO
0
440
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
1
340
Event Storming
hschwentner
3
1.3k
CopilotKit + AG-UIを学ぶ
nearme_tech
PRO
1
110
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
96
14k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
480
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
82
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Optimizing for Happiness
mojombo
379
71k
It's Worth the Effort
3n
188
29k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Facilitating Awesome Meetings
lara
57
6.8k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
380
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
860
Music & Morning Musume
bryan
47
7.1k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
89
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