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
120
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
120
Docker: What It Is and Why You Should Care
alexanderclark
0
110
Other Decks in Programming
See All in Programming
Composing an API with Kotlin (Kotlin Dev Day 2022)
zsmb
0
260
Licences open source : entre guerre de clochers et radicalité
pylapp
1
260
Learning DDD輪読会#4 / Learning DDD Book Club #4
suzushin54
1
130
Is Rust a great language for building Kubernetes ecosystem
deepu105
0
140
Swift Concurrencyによる安全で快適な非同期処理
tattn
2
310
Go API クライアントの実装 〜Go Conference に載せれなかったTIPS〜
yyoshiki41
0
190
확장 가능한 테라폼 코드 관리 (Scalable Terraform Code Management)
posquit0
1
320
Let's make a contract: the art of designing a Java API
mariofusco
0
160
Monadic Java
mariofusco
4
260
Micro Frontends with Module Federation: Beyond the Basics @jax2022
manfredsteyer
PRO
1
290
インフラエンジニアの多様性と評価、またはキャリアへのつなげ方 / Careers as infrastructure engineers
katsuhisa91
0
500
UI State Modeling 어떤게 좋을까?
laco2951
1
220
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
349
27k
The Invisible Side of Design
smashingmag
289
48k
The Invisible Customer
myddelton
110
11k
The Language of Interfaces
destraynor
148
20k
The Art of Programming - Codeland 2020
erikaheidi
31
5.8k
Code Reviewing Like a Champion
maltzj
506
37k
Fireside Chat
paigeccino
11
1.3k
Learning to Love Humans: Emotional Interface Design
aarron
261
37k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_i
21
14k
Practical Orchestrator
shlominoach
178
8.6k
Principles of Awesome APIs and How to Build Them.
keavy
113
15k
Bash Introduction
62gerente
596
210k
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