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
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
On-the-fly Suggestions of Rewriting Method Deprecations
ohbarye
1
4.7k
AI時代の開発者評価について
ayumuu
0
230
ComposeでWebアプリを作る技術
tbsten
0
130
プロダクト横断分析に役立つ、事前集計しないサマリーテーブル設計
hanon52_
3
530
RubyKaigi Dev Meeting 2025
tenderlove
1
1.3k
複雑なフォームの jotai 設計 / Designing jotai(state) for Complex Forms #layerx_frontend
izumin5210
6
1.5k
파급효과: From AI to Android Development
l2hyunwoo
0
160
カウシェで Four Keys の改善を試みた理由
ike002jp
1
120
Rubyの!メソッドをちゃんと理解する
alstrocrack
1
120
Creating Awesome Change in SmartNews! En
martin_lover
0
110
Memory API : Patterns, Performance et Cas d'Utilisation
josepaumard
1
170
Instrumentsを使用した アプリのパフォーマンス向上方法
hinakko
0
230
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
5
550
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Making Projects Easy
brettharned
116
6.2k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
GraphQLとの向き合い方2022年版
quramy
46
14k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
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