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
要はバランスからの卒業 #yumemi_grow
kajitack
0
140
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
1.8k
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
500
Are We Really Coding 10× Faster with AI?
kohzas
0
150
空間オーディオの活用
objectiveaudio
0
150
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
300
AWSはOSSをどのように 考えているのか?
akihisaikeda
0
110
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
350
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
380
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
130
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
190
SkillsをS3 Filesに置く時のあれこれ
watany
3
1.5k
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
190
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
340
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
46
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
180
WENDY [Excerpt]
tessaabrams
10
37k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Bash Introduction
62gerente
615
210k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Statistics for Hackers
jakevdp
799
230k
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