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
180
MiddlewarePattern.pdf
ayato
September 11, 2015
Tweet
Share
More Decks by ayato
See All by ayato
マイクロサービス内で動くAPIをF#で書いている
ayato0211
1
960
Clojureという言語が私逹にもたらしたもの
ayato0211
6
3.1k
3年間考え続けてきたWebアプリケーションにおけるテストの話
ayato0211
3
270
Re:REPL-Driven Development
ayato0211
3
1.3k
Meta Template Engine
ayato0211
2
1.1k
超変換! Hiccup data structure!!
ayato0211
2
620
About Integrant
ayato0211
0
570
Muscle Assert
ayato0211
0
280
Clojureを用いたWebアプリケーション開発
ayato0211
2
3.2k
Other Decks in Programming
See All in Programming
Register is more than clipboard
satorunooshie
1
470
イベントストーミングのはじめかた / Getting Started with Event Storming
nrslib
1
510
Java_プロセスのメモリ監視の落とし穴_NMT_で見抜けない_glibc_キャッシュ問題_.pdf
ntt_dsol_java
0
190
複数チーム並行開発下でのコード移行アプローチ ~手動 Codemod から「生成AI 活用」への進化
andpad
0
170
「10分以内に機能を消せる状態」 の実現のためにやっていること
togishima
1
370
「正規表現をつくる」をつくる / make "make regex"
makenowjust
1
420
組織もソフトウェアも難しく考えない、もっとシンプルな考え方で設計する #phpconfuk
o0h
PRO
10
4.3k
CloudNative Days Winter 2025: 一週間で作る低レイヤコンテナランタイム
ternbusty
4
720
ビルドプロセスをデバッグしよう!
yt8492
0
310
Inside of Swift Export
giginet
PRO
1
560
Nitro v3
kazupon
2
300
Module Harmony
petamoriken
2
340
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1032
470k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
GraphQLとの向き合い方2022年版
quramy
49
14k
Statistics for Hackers
jakevdp
799
220k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Designing for humans not robots
tammielis
254
26k
Docker and Python
trallard
46
3.6k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
1.8k
Music & Morning Musume
bryan
46
6.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
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