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
310
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
290
Docker: What It Is and Why You Should Care
alexanderclark
0
310
Other Decks in Programming
See All in Programming
[Fin-JAWS 第38回 ~re:Invent 2024 金融re:Cap~]FaultInjectionServiceアップデート@pre:Invent2024
shintaro_fukatsu
0
400
テストをしないQAエンジニアは何をしているか?
nealle
0
130
Amazon Q Developer Proで効率化するAPI開発入門
seike460
PRO
0
100
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
140
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
320
【PHP】破壊的バージョンアップと戦った話〜決断と説得
satoshi256kbyte
0
120
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
120
AHC041解説
terryu16
0
590
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
2
730
Pulsar2 を雰囲気で使ってみよう
anoken
0
220
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
110
動作確認やテストで漏れがちな観点3選
starfish719
6
990
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
6
240
We Have a Design System, Now What?
morganepeng
51
7.4k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
9
1.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Code Review Best Practice
trishagee
66
17k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Faster Mobile Websites
deanohume
306
31k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Producing Creativity
orderedlist
PRO
343
39k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
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