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
Reitit使ってみた
Search
valerauko
November 29, 2018
Programming
0
390
Reitit使ってみた
ClojureのルーティングライブラリReititを使っての感想などのお話
valerauko
November 29, 2018
Tweet
Share
More Decks by valerauko
See All by valerauko
CIにどこまで任せるのか?
valerauko
0
240
分解に救われる
valerauko
0
100
Other Decks in Programming
See All in Programming
Building, Deploying, and Monitoring Ruby Web Applications with Falcon (Kaigi on Rails 2025)
ioquatix
4
2k
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
220
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
370
Go言語はstack overflowの夢を見るか?
logica0419
0
190
Pull-Requestの内容を1クリックで動作確認可能にするワークフロー
natmark
2
490
Range on Rails ―「多重範囲型」という新たな選択肢が、複雑ロジックを劇的にシンプルにしたワケ
rizap_tech
0
110
Introducing ReActionView: A new ActionView-Compatible ERB Engine @ Kaigi on Rails 2025, Tokyo, Japan
marcoroth
3
1k
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
220
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
160
Serena MCPのすすめ
wadakatu
4
980
バッチ処理を「状態の記録」から「事実の記録」へ
panda728
PRO
0
150
XP, Testing and ninja testing ZOZ5
m_seki
3
620
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
32
2.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Faster Mobile Websites
deanohume
310
31k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Docker and Python
trallard
46
3.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Into the Great Unknown - MozCon
thekraken
40
2.1k
Code Reviewing Like a Champion
maltzj
526
40k
The Illustrated Children's Guide to Kubernetes
chrisshort
49
51k
Leading Effective Engineering Teams in the AI Era
addyosmani
1
190
Transcript
Reitit使ってみた エル [valerauko]
Reititはルーティング用のライブラリ • フィンランド語で「ルート」 • ringのmiddlewareやpedestalのinterceptorも使える • Compojureとかをすごく意識してる • ルートはデータ •
API用の便利機能が豊富 • かなり速い
ルートがデータ? ["/.well-known" {:summary "WebFinger endpoints" :swagger {:tags ["WebFinger"]}} ["/host-meta" {:get
{:summary "Host metadata" :swagger {:produces #{"application/xrd+xml" "application/xml"}} :responses {200 {:body any?}} :handler host-meta}}] ["/webfinger" {:get {:summary "WebFinger endpoint for users" :swagger {:produces #{"application/xrd+xml" "application/jrd+json"}} :parameters {:query {:resource ::spec/resource}} :responses {200 {:body any?}} :handler resource}}]]
なんで速いのか • ルートがただのデータでコンパイル時に完結する ◦ なおルートのバッティングを許さない前提 • フラットなデータ構造体になるので「検索」が速い • OKのレスポンス(ルートがある)に最適化されてる ◦
/hello -> /hello/みたいなリダイレクトとか ◦ 存在しないルートとかは別に扱われる
引っかかりそうなところ • ルートのコンパイル時、ミドルウェアがルートにいちいちコピーされる ◦ PRO 探さなくて済むから速いのは速い ◦ CON 何かの共通の状態(ステート)があるとバグる •
考えずにringのdefault-middleware付けてもセッションが動かない ◦ 関数だけルートにコピーされて、それぞれ共有されない session-store作ってしまう ◦ 開発者いわく「interceptorなら動くはず」とのこと • middlewareの関数はモックできない ◦ with-redefsしても、すでにルートにコピーされてるから置き換えられない
便利機能 • ルートに任意のデータも紐付けられる ◦ {:role #{:roles/admin}}みたいにエンドポイントに必要な権限 ◦ ミドルウェアやハンドラで確認に使える • swagger対応
◦ API開発ならものすごく便利 ◦ UIまであるので手でcurl打たなくて済む • coercion (形式強制) ◦ リクエストもレスポンスも形式が定義できる ◦ clojure.spec, schema, metosin製のdata-spec ◦ middleware入れると形に合ってないの弾く
参考文献 • https://github.com/metosin/reitit • Clojurians #reitit • https://github.com/valerauko