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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
AI & Enginnering
codelynx
0
110
Data-Centric Kaggle
isax1015
2
770
SourceGeneratorのススメ
htkym
0
190
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
110
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
190
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
380
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
560
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
280
Basic Architectures
denyspoltorak
0
670
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
200
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
910
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Producing Creativity
orderedlist
PRO
348
40k
It's Worth the Effort
3n
188
29k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
4 Signs Your Business is Dying
shpigford
187
22k
How to make the Groovebox
asonas
2
1.9k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
340
Mind Mapping
helmedeiros
PRO
0
81
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
210
Marketing to machines
jonoalderson
1
4.6k
How to train your dragon (web standard)
notwaldorf
97
6.5k
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