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
330
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
320
Docker: What It Is and Why You Should Care
alexanderclark
0
330
Other Decks in Programming
See All in Programming
C++20 射影変換
faithandbrave
0
500
Result型で“失敗”を型にするPHPコードの書き方
kajitack
4
150
Using AI Tools Around Software Development
inouehi
0
1.3k
ktr0731/go-mcpでMCPサーバー作ってみた
takak2166
0
170
関数型まつり2025登壇資料「関数プログラミングと再帰」
taisontsukada
2
840
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
160
FormFlow - Build Stunning Multistep Forms
yceruto
1
190
XSLTで作るBrainfuck処理系
makki_d
0
210
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
210
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
4
860
ASP.NETアプリケーションのモダナイズ インフラ編
tomokusaba
1
400
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
780
Featured
See All Featured
Building an army of robots
kneath
306
45k
VelocityConf: Rendering Performance Case Studies
addyosmani
330
24k
Code Review Best Practice
trishagee
68
18k
Bash Introduction
62gerente
614
210k
Statistics for Hackers
jakevdp
799
220k
Faster Mobile Websites
deanohume
307
31k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
Done Done
chrislema
184
16k
Writing Fast Ruby
sferik
628
61k
Designing Experiences People Love
moore
142
24k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Scaling GitHub
holman
459
140k
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