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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
540
AI時代の認知負荷との向き合い方
optfit
0
130
CSC307 Lecture 05
javiergs
PRO
0
490
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
530
CSC307 Lecture 09
javiergs
PRO
1
810
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
150
AI & Enginnering
codelynx
0
110
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
220
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
Patterns of Patterns
denyspoltorak
0
1.3k
Package Management Learnings from Homebrew
mikemcquaid
0
180
Featured
See All Featured
Designing for Timeless Needs
cassininazir
0
130
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
110
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
75
Practical Orchestrator
shlominoach
191
11k
Deep Space Network (abreviated)
tonyrice
0
44
We Have a Design System, Now What?
morganepeng
54
8k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Test your architecture with Archunit
thirion
1
2.1k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
120
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
250
Designing for Performance
lara
610
70k
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