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
270
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
250
Docker: What It Is and Why You Should Care
alexanderclark
0
260
Other Decks in Programming
See All in Programming
MIERUNE BBQにおけるユーザー中心設計()
mierune
PRO
1
110
大規模マルチテナントを解決するYugabyteDBという選択肢
nnaka2992
1
250
Polarsの成長: v0.14からv1.0までの変遷と今後の展望
zerebom
1
350
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
1.9k
OpenAI/Gemini APIを使って EPUBを翻訳するCLIツールをつくってみた
tomiyan
0
790
Android開発者のための Kotlin Multiplatform入門
ntaro
0
190
feature環境をGitHub ActionsとCloudFormationでいい感じに管理する
nealle
2
310
12年前の『型システム入門』翻訳の思い出話
mame
11
1.2k
Advanced App Shrinking Techniques
cbeyls
2
150
生成AIをkintoneに連携してみた
hideg
0
230
CSC307 Lecture 12
javiergs
PRO
0
220
Clean Architecture by TypeScript & NestJS
ryounasso
0
150
Featured
See All Featured
How GitHub Uses GitHub to Build GitHub
holman
471
290k
Designing Experiences People Love
moore
136
23k
How to Think Like a Performance Engineer
csswizardry
4
590
Adopting Sorbet at Scale
ufuk
71
8.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
248
12k
Being A Developer After 40
akosma
72
580k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
36
9.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.3k
Agile that works and the tools we love
rasmusluckow
325
20k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
245
1.2M
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