(def app
(ring/ring-handler
(ring/router
- ["/ping" {:name ::ping
+ ["/ping" {:name ::ping
:get handler
:post handler}])))
@@ -369,7 +369,7 @@
Reverse routing:
(-> app
(ring/get-router)
- (reitit/match-by-name ::ping)
+ (reitit/match-by-name ::ping)
:path)
; "/ping"
@@ -382,9 +382,9 @@
A middleware and a handler:
(defn wrap [handler id]
(fn [request]
- (handler (update request ::acc (fnil conj []) id))))
+ (handler (update request ::acc (fnil conj []) id))))
-(defn handler [{:keys [::acc]}]
+(defn handler [{:keys [::acc]}]
{:status 200, :body (conj acc :handler)})
App with nested middleware:
@@ -435,14 +435,14 @@
(def wrap2
(middleware/create
- {:name ::wrap2
+ {:name ::wrap2
:description "a nice little mw, takes 1 arg."
:wrap wrap}))
As plain map:
;; plain map
(def wrap3
- {:name ::wrap3
+ {:name ::wrap3
:description "a nice little mw, :api as arg"
:wrap (fn [handler]
(wrap handler :api))})
@@ -455,8 +455,8 @@
(require '[clojure.set :as set])
(defn wrap-enforce-roles [handler]
- (fn [{:keys [::roles] :as request}]
- (let [required (some-> request (ring/get-match) :meta ::roles)]
+ (fn [{:keys [::roles] :as request}]
+ (let [required (some-> request (ring/get-match) :meta ::roles)]
(if (and (seq required) (not (set/intersection required roles)))
{:status 403, :body "forbidden"}
(handler request)))))
@@ -469,7 +469,7 @@
(ring/router
[["/api"
["/ping" handler]
- ["/admin" {::roles #{:admin}}
+ ["/admin" {::roles #{:admin}}
["/ping" handler]]]]
{:meta {:middleware [wrap-enforce-roles]}})))
@@ -482,7 +482,7 @@
; {:status 403, :body "forbidden"}
Authorized access to guarded route:
-(app {:request-method :get, :uri "/api/admin/ping", ::roles #{:admin}})
+(app {:request-method :get, :uri "/api/admin/ping", ::roles #{:admin}})
; {:status 200, :body "ok"}
@@ -528,7 +528,7 @@
diff --git a/routing/route_conflicts.html b/routing/route_conflicts.html
index 8454e402..c5c1c683 100644
--- a/routing/route_conflicts.html
+++ b/routing/route_conflicts.html
@@ -386,7 +386,7 @@
diff --git a/routing/route_metadata.html b/routing/route_metadata.html
index cb65751d..be5f76d7 100644
--- a/routing/route_metadata.html
+++ b/routing/route_metadata.html
@@ -327,15 +327,15 @@
A router based on nested route tree:
(def router
(reitit/router
- ["/api" {:interceptors [::api]}
- ["/ping" ::ping]
+ ["/api" {:interceptors [::api]}
+ ["/ping" ::ping]
["/admin" {:roles #{:admin}}
- ["/users" ::users]
- ["/db" {:interceptors [::db]
+ ["/users" ::users]
+ ["/db" {:interceptors [::db]
:roles ^:replace #{:db-admin}}
["/:db" {:parameters {:db String}}
- ["/drop" ::drop-db]
- ["/stats" ::db-stats]]]]]))
+ ["/drop" ::drop-db]
+ ["/stats" ::db-stats]]]]]))
Resolved route tree:
(reitit/routes router)
@@ -408,7 +408,7 @@
diff --git a/routing/route_syntax.html b/routing/route_syntax.html
index ca2ce78e..fbcbd4e5 100644
--- a/routing/route_syntax.html
+++ b/routing/route_syntax.html
@@ -330,8 +330,8 @@
["/pong"]]
Routes with meta-data:
-[["/ping" ::ping]
- ["/pong" {:name ::pong}]]
+[["/ping" ::ping]
+ ["/pong" {:name ::pong}]]
Routes with path and catch-all parameters:
[["/users/:user-id"]
@@ -339,15 +339,15 @@
Nested routes with meta-data:
["/api"
- ["/admin" {:middleware [::admin]}
- ["/user" ::user]
- ["/db" ::db]
- ["/ping" ::ping]]
+ ["/admin" {:middleware [::admin]}
+ ["/user" ::user]
+ ["/db" ::db]
+ ["/ping" ::ping]]
Same routes flattened:
-[["/api/admin/user" {:middleware [::admin], :name ::user}
- ["/api/admin/db" {:middleware [::admin], :name ::db}
- ["/api/ping" ::ping]]
+[["/api/admin/user" {:middleware [::admin], :name ::user}
+ ["/api/admin/db" {:middleware [::admin], :name ::db}
+ ["/api/ping" ::ping]]
@@ -388,7 +388,7 @@
diff --git a/routing/routers.html b/routing/routers.html
index 66e281e7..5231c52a 100644
--- a/routing/routers.html
+++ b/routing/routers.html
@@ -331,8 +331,8 @@
(def router
(reitit/router
[["/api"
- ["/ping" ::ping]
- ["/user/:id" ::user]]]))
+ ["/ping" ::ping]
+ ["/user/:id" ::user]]]))
:mixed-router is created (both static & wild routes are found):
(reitit/router-name router)
@@ -359,18 +359,18 @@
; :params {:id "1"}}
Name-based (reverse) routing
-(reitit/match-by-name router ::user)
+(reitit/match-by-name router ::user)
; #PartialMatch{:template "/api/user/:id",
; :meta {:name :user/user},
; :result nil,
; :params nil,
; :required #{:id}}
-(reitit/partial-match? (reitit/match-by-name router ::user))
+(reitit/partial-match? (reitit/match-by-name router ::user))
; true
Only a partial match. Let's provide the path-parameters:
-(reitit/match-by-name router ::user {:id "1"})
+(reitit/match-by-name router ::user {:id "1"})
; #Match{:template "/api/user/:id"
; :meta {:name :user/user}
; :path "/api/user/1"
@@ -378,7 +378,7 @@
; :params {:id "1"}}
There is also a exception throwing version:
-(reitit/match-by-name! router ::user)
+(reitit/match-by-name! router ::user)
; ExceptionInfo missing path-params for route /api/user/:id: #{:id}
@@ -424,7 +424,7 @@
diff --git a/validating.html b/validating.html
index 69035d8f..46fddad6 100644
--- a/validating.html
+++ b/validating.html
@@ -451,7 +451,7 @@