Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Building with Rack
Alexander Clark
February 23, 2016
Programming
2
150
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
160
Docker: What It Is and Why You Should Care
alexanderclark
0
160
Other Decks in Programming
See All in Programming
AWSとCPUのムフフな関係
cmdemura
0
480
Ruby Pattern Matching
bkuhlmann
0
610
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
610
Functional Fun in Kotlin
nomisrev
1
100
Remix + Cloudflare Pages + D1 で ポケモン SV のレンタルチームを検索できるアプリを作ってみた
kuroppe1819
4
1.4k
PHP でガチの電卓を作る
memory1994
PRO
1
110
Gradle build: The time is now
nonews
1
490
jq at the Shortcuts
cockscomb
1
440
僕が考えた超最強のKMMアプリの作り方
spbaya0141
0
180
Swift Observation
shiz
4
290
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
42k
Azure Functionsをサクッと開発、サクッとデプロイ/vscodeconf2023-baba
nina01
1
350
Featured
See All Featured
Design by the Numbers
sachag
271
18k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
6
840
Why You Should Never Use an ORM
jnunemaker
PRO
49
7.9k
Principles of Awesome APIs and How to Build Them.
keavy
117
15k
Why Our Code Smells
bkeepers
PRO
326
55k
VelocityConf: Rendering Performance Case Studies
addyosmani
317
22k
Done Done
chrislema
178
14k
Robots, Beer and Maslow
schacon
154
7.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
15
1.2k
How to name files
jennybc
47
73k
Into the Great Unknown - MozCon
thekraken
2
300
YesSQL, Process and Tooling at Scale
rocio
159
12k
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