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
340
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
330
Docker: What It Is and Why You Should Care
alexanderclark
0
350
Other Decks in Programming
See All in Programming
Vueのバリデーション、結局どれを選べばいい? ― 自作バリデーションの限界と、脱却までの道のり ― / Which Vue Validation Library Should We Really Use? The Limits of Self-Made Validation and How I Finally Moved On
neginasu
3
1.8k
TransformerからMCPまで(現代AIを理解するための羅針盤)
mickey_kubo
7
6k
One Enishi After Another
snoozer05
PRO
0
180
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
320
マンガアプリViewerの大画面対応を考える
kk__777
0
450
CSC509 Lecture 09
javiergs
PRO
0
280
CSC509 Lecture 11
javiergs
PRO
0
290
AIと人間の共創開発!OSSで試行錯誤した開発スタイル
mae616
2
870
品質ワークショップをやってみた
nealle
0
940
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
1.3k
Blazing Fast UI Development with Compose Hot Reload (droidcon London 2025)
zsmb
0
450
ボトムアップの生成AI活用を推進する社内AIエージェント開発
aku11i
0
1.5k
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Writing Fast Ruby
sferik
630
62k
Speed Design
sergeychernyshev
32
1.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
We Have a Design System, Now What?
morganepeng
54
7.9k
It's Worth the Effort
3n
187
28k
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