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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Alexander Clark
February 23, 2016
Programming
380
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
150
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
300
New "Type" system on PicoRuby
pocke
1
1k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
170
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
740
dRuby over BLE
makicamel
2
390
AI 輔助遺留系統現代化的經驗分享
jame2408
1
970
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
RTSPクライアントを自作してみた話
simotin13
0
630
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
190
Featured
See All Featured
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
180
BBQ
matthewcrist
89
10k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
540
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Deep Space Network (abreviated)
tonyrice
0
210
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
400
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