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
MiddlewarePattern.pdf
Search
ayato
September 11, 2015
Programming
0
150
MiddlewarePattern.pdf
ayato
September 11, 2015
Tweet
Share
More Decks by ayato
See All by ayato
Clojureという言語が私逹にもたらしたもの
ayato0211
5
2.7k
3年間考え続けてきたWebアプリケーションにおけるテストの話
ayato0211
3
200
Re:REPL-Driven Development
ayato0211
3
1.1k
Meta Template Engine
ayato0211
2
850
超変換! Hiccup data structure!!
ayato0211
2
520
About Integrant
ayato0211
0
430
Muscle Assert
ayato0211
0
190
Clojureを用いたWebアプリケーション開発
ayato0211
2
2.8k
翻訳にまつわるエトセトラ
ayato0211
6
1.1k
Other Decks in Programming
See All in Programming
15分間でふんわり理解するDocker @ Matsuriba MAX
ukwhatn
PRO
1
340
Why 1 + 1 = 2 in Swift?
1plus4
1
250
オブジェクト指向は必要なのか / Is object-oriented needed?
kishida
27
19k
実践!RDRAを活用した既存システムの仕様変更 / Specification Changes in Existing Systems Utilizing RDRA
imamotohikaru
0
2.8k
GitHub Copilot Tips and Tricks
yuichielectric
26
7.5k
Ruby製社内ツールのGo移行
bgpat
2
270
Learning PHP and Static Analysis with PHP Parser
inouehi
1
250
クソコード動画『カプセル化 Mk-II』 で考える 上手くカプセル化できない理由 / encapsulation2
minodriven
11
8.1k
Material 3で Material 2ぽい見た目にする
numeroanddev
2
250
受託開発でGitLab CI を活用していく
xiombatsg
1
130
document.write再考
brn
5
2.5k
Open Source Swiftc Workshop
kitasuke
1
290
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
225
51k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
Large-scale JavaScript Application Architecture
addyosmani
501
110k
Ruby is Unlike a Banana
tanoku
95
10k
[RailsConf 2023] Rails as a piece of cake
palkan
21
3.8k
Designing the Hi-DPI Web
ddemaree
275
33k
The Language of Interfaces
destraynor
150
23k
Atom: Resistance is Futile
akmur
258
25k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
1
3.3k
For a Future-Friendly Web
brad_frost
170
8.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
657
120k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
Transcript
Middleware Pattern @_ayato_p/Cybozu Startups, Inc.
(def _ayato_p {:name "あやぴー" :lang
[:clojure :ruby :javascript] :company "Cybozu Startups, Inc."})
(def _ayato_p {:name "あやぴー" :lang
[:clojure :ruby :javascript] :company "Cybozu Startups, Inc."}) Clojure 歴、半年
Agenda Ring Ring Middleware Middleware Pattern
Ring
Ring サーバーを抽象化する仕様/デファクトスタンダード Ring Handler, Requests, Responses, Middleware 公式には
jetty のアダプタがある 最近で Ring インターフェイスを実装したものだと Immutant などがある
Ring Middleware
Ring Middleware ただの高階関数 Ring Middleware の場合、 Handler を受け取って
Request を受け取る関数を返すような書き方されてる
Ring Middleware (defn wrap-secret-key[handler secret-key] (fn [req]
(handler (assoc-in req [:params :secret-key] secret-key)))) (defn make-handler [handler] (-> handler (wrap-secret-key "This is secret!!") wrap-something wrap-anything wrap-defaults)) (app (make-handler (get-ring-handler)))
Middleware Pattern
Middleware Pattern Ring Middleware はひとつの Middleware Pattern 例 他には
Boot でも適用されている
Use case ユーザーの入力を受け取って、関数を適用するか決めたい config ファイルを使って、関数を適用するか決めたい LazySeq に適用する関数をオプションから決めたい
-> Composable な関数を作りたい!!
Conclusion Composable な関数を書くお供に Middleware Pattern を活用しよう
Enjoy Clojure