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
380
Reitit使ってみた
ClojureのルーティングライブラリReititを使っての感想などのお話
valerauko
November 29, 2018
Tweet
Share
More Decks by valerauko
See All by valerauko
CIにどこまで任せるのか?
valerauko
0
230
分解に救われる
valerauko
0
100
Other Decks in Programming
See All in Programming
💎 My RubyKaigi Effect in 2025: Top Ruby Companies 🌐
yasulab
PRO
1
130
Step up the performance game with Spring Boot and Project Leyden
mhalbritter
0
170
バリデーションライブラリ徹底比較
nayuta999999
1
590
從零到一:搭建你的第一個 Observability 平台
blueswen
0
310
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
2
1.9k
少数精鋭エンジニアがフルスタック力を磨く理由 -そしてAI時代へ-
rebase_engineering
0
150
ktr0731/go-mcpでMCPサーバー作ってみた
takak2166
0
120
Agent Rules as Domain Parser
yodakeisuke
1
450
機械学習って何? 5分で解説頑張ってみる
kuroneko2828
0
180
Babylon.js 8.0のアプデ情報を 軽率にキャッチアップ / catch-up-babylonjs-8
drumath2237
0
120
Gleamという選択肢
comamoca
3
310
Cloudflare Realtime と Workers でつくるサーバーレス WebRTC
nekoya3
0
360
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
53
11k
Being A Developer After 40
akosma
90
590k
A Tale of Four Properties
chriscoyier
159
23k
Designing for humans not robots
tammielis
253
25k
Become a Pro
speakerdeck
PRO
28
5.4k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
6
670
BBQ
matthewcrist
89
9.7k
Building Applications with DynamoDB
mza
95
6.4k
The World Runs on Bad Software
bkeepers
PRO
68
11k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
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