mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
943 B
943 B
Name-based routing
All routes which :name route data defined, can be matched by name.
Listing all route names:
(r/route-names router)
; [:user/ping :user/user]
Matching by name:
(r/match-by-name router ::user)
; #PartialMatch{:template "/api/user/:id",
; :meta {:name :user/user},
; :result nil,
; :params nil,
; :required #{:id}}
(r/partial-match? (r/match-by-name router ::user))
; true
We only got a partial match as we didn't provide the needed path-parameters. Let's provide the them too:
(r/match-by-name router ::user {:id "1"})
; #Match{:template "/api/user/:id"
; :meta {:name :user/user}
; :path "/api/user/1"
; :result nil
; :params {:id "1"}}
There is also a exception throwing version:
(r/match-by-name! router ::user)
; ExceptionInfo missing path-params for route /api/user/:id: #{:id}