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
170
MiddlewarePattern.pdf
ayato
September 11, 2015
Tweet
Share
More Decks by ayato
See All by ayato
Clojureという言語が私逹にもたらしたもの
ayato0211
6
3k
3年間考え続けてきたWebアプリケーションにおけるテストの話
ayato0211
3
240
Re:REPL-Driven Development
ayato0211
3
1.3k
Meta Template Engine
ayato0211
2
1.1k
超変換! Hiccup data structure!!
ayato0211
2
580
About Integrant
ayato0211
0
530
Muscle Assert
ayato0211
0
250
Clojureを用いたWebアプリケーション開発
ayato0211
2
3.1k
翻訳にまつわるエトセトラ
ayato0211
6
1.2k
Other Decks in Programming
See All in Programming
State of Namespace
tagomoris
4
710
プロダクト横断分析に役立つ、事前集計しないサマリーテーブル設計
hanon52_
2
380
Being an ethical software engineer
xgouchet
PRO
0
210
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
180
Django for Data Science (Boston Python Meetup, March 2025)
wsvincent
0
320
AWSで雰囲気でつくる! VRChatの写真変換ピタゴラスイッチ
anatofuz
0
140
Empowering Developers with HTML-Aware ERB Tooling @ RubyKaigi 2025, Matsuyama, Ehime
marcoroth
1
230
AIコーディングワークフローの試行 〜AIエージェント×ワークフローでの自動化を目指して〜
rkaga
2
3.4k
Kamal 2 – Get Out of the Cloud
aleksandrov
1
180
PHP で学ぶ OAuth 入門
azuki
1
120
エンジニア未経験が最短で戦力になるためのTips
gokana
0
260
Vibe Codingをせずに Clineを使っている
watany
17
6k
Featured
See All Featured
Practical Orchestrator
shlominoach
186
10k
Visualization
eitanlees
146
16k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
178
52k
Faster Mobile Websites
deanohume
306
31k
Docker and Python
trallard
44
3.3k
Site-Speed That Sticks
csswizardry
5
480
Making the Leap to Tech Lead
cromwellryan
133
9.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
23
2.6k
Building an army of robots
kneath
304
45k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
The Cult of Friendly URLs
andyhume
78
6.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
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