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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Alexander Clark
February 23, 2016
Programming
360
2
Share
Building with Rack
Let's build a Rack app!
Alexander Clark
February 23, 2016
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
350
Docker: What It Is and Why You Should Care
alexanderclark
0
370
Other Decks in Programming
See All in Programming
L’IA au service des devs : Anatomie d'un assistant de Code Review
toham
0
190
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
5
2.4k
RSAが破られる前に知っておきたい 耐量子計算機暗号(PQC)入門 / Intro to PQC: Preparing for the Post-RSA Era
mackey0225
3
110
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
230
PHPで TLSのプロトコルを実装してみる
higaki_program
0
730
Claude Code Skill入門
mayahoney
0
460
Feature Toggle は捨てやすく使おう
gennei
0
400
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
140
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
180
へんな働き方
yusukebe
6
2.9k
存在論的プログラミング: 時間と存在を記述する
koriym
5
750
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
250
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
260
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
250
How GitHub (no longer) Works
holman
316
150k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
700
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
160
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
250
The Language of Interfaces
destraynor
162
26k
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