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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
210
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
410
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
1.5k
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
160
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.3k
AIエージェントと協働するCLI開発 — BunとOpenClawで学んだこと
yoshikouki
1
230
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
ふつうのFeature Flag実践入門
irof
7
3.5k
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
190
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
2
370
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
420
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
270
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
160
Building Applications with DynamoDB
mza
96
7.1k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
130
4 Signs Your Business is Dying
shpigford
187
22k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
600
Information Architects: The Missing Link in Design Systems
soysaucechin
0
950
Making the Leap to Tech Lead
cromwellryan
135
9.9k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Code Reviewing Like a Champion
maltzj
528
40k
Leo the Paperboy
mayatellez
7
1.8k
How to Ace a Technical Interview
jacobian
281
24k
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