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
340
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
330
Docker: What It Is and Why You Should Care
alexanderclark
0
350
Other Decks in Programming
See All in Programming
uniqueパッケージの内部実装を支えるweak pointerの話
magavel
0
960
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
140
どの様にAIエージェントと 協業すべきだったのか?
takefumiyoshii
2
640
明日から始めるリファクタリング
ryounasso
0
130
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
460
Domain-centric? Why Hexagonal, Onion, and Clean Architecture Are Answers to the Wrong Question
olivergierke
2
790
なぜあの開発者はDevRelに伴走し続けるのか / Why Does That Developer Keep Running Alongside DevRel?
nrslib
3
390
Cloudflare AgentsとAI SDKでAIエージェントを作ってみた
briete
0
130
CI_CD「健康診断」のススメ。現場でのボトルネック特定から、健康診断を通じた組織的な改善手法
teamlab
PRO
0
200
CSC305 Lecture 02
javiergs
PRO
1
260
CSC305 Lecture 06
javiergs
PRO
0
210
理論と実務のギャップを超える
eycjur
0
120
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
Documentation Writing (for coders)
carmenintech
75
5k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
620
Automating Front-end Workflow
addyosmani
1371
200k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
Embracing the Ebb and Flow
colly
88
4.8k
Site-Speed That Sticks
csswizardry
11
890
Fireside Chat
paigeccino
40
3.7k
Docker and Python
trallard
46
3.6k
Scaling GitHub
holman
463
140k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
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