From c3ffddc6308a4ad9ec8ea53c2d2cea7a197d8508 Mon Sep 17 00:00:00 2001
From: Automatic build WIP WIP Reitit includes two browser history integrations. Functions follow HTML5 History API:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
reitit.frontend provides few useful functions wrapping core functions:
match-by-path version which parses a URI using JavaScript, including
@@ -767,7 +798,7 @@ React breaking due to errors).
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
Frontend browser integration
-push-state to change route, replace-state
to change route without leaving previous entry in browser history.
WIP
+Modules:
reitit - all bundledreitit-core - the routing corereitit-ring with data-driven middlewarereitit-ring - a ring routerreitit-middleware - common middleware for reitit-ringreitit-spec clojure.spec coercionreitit-schema Schema coercionreitit-swagger Swagger2 apidocsreitit-swagger-ui Integrated Swagger UI.reitit-frontend Tools for frontend routing.To use Reitit, add the following dependency to your project:
+Bubblin' under:
+reitit-http http-routing with Pedestal-style Interceptors (WIP)reitit-sieppari support for Sieppari Interceptors (WIP)All bundled:
[metosin/reitit "0.2.0-SNAPSHOT"]
Optionally, the parts can be required separately:
[metosin/reitit-core "0.2.0-SNAPSHOT"]
-[metosin/reitit-ring "0.2.0-SNAPSHOT"]
+
+;; coercion
[metosin/reitit-spec "0.2.0-SNAPSHOT"]
[metosin/reitit-schema "0.2.0-SNAPSHOT"]
+
+;; ring helpers
+[metosin/reitit-ring "0.2.0-SNAPSHOT"]
+[metosin/reitit-middleware "0.2.0-SNAPSHOT"]
+
+;; swagger-support for ring & http
[metosin/reitit-swagger "0.2.0-SNAPSHOT"]
[metosin/reitit-swagger-ui "0.2.0-SNAPSHOT"]
-[metosin/frontend "0.1.4-SNAPSHOT"]
+
+;; frontend helpers (alpha)
+[metosin/reitit-frontend "0.2.0-SNAPSHOT"]
+
+;; http with interceptors (alpha)
+[metosin/reitit-http "0.2.0-SNAPSHOT"]
+[metosin/reitit-sieppari "0.2.0-SNAPSHOT"]
-For discussions, there is a #reitit channel in Clojurians slack.
+There is #reitit in Clojurians Slack for discussion & help.
(require '[reitit.core :as r])
@@ -877,7 +931,7 @@
diff --git a/interceptors.html b/interceptors.html
index 021a2884..7ca01c17 100644
--- a/interceptors.html
+++ b/interceptors.html
@@ -283,91 +283,7 @@
As reitit-core works with both Clojure & ClojureScript, one can have a shared routing table for both the frontend and the backend application, using the Clujore Common Files.
For backend, you need to define a :handler for the request processing, for fronend, :name enables the use of reverse routing.
There are multiple options to use shared routing table.
+;; define the handlers for for clojure
+#?(:clj (declare get-kikka))
+#?(:clj (declare post-kikka))
+
+;; :name for both, :handler just for clojure
+(def routes
+ ["/kikka"
+ {:name ::kikka
+ :get #?(:clj {:handler get-kikka})
+ :post #?(:clj {:handler post-kikka})}]
+
+raw-routes can have any non-sequential data as a route argument, which gets expanded using the :expand option given to the reitit.core.router function. It defaults to reitit.core/expand multimethod.
First, define the common routes (in a .cljc file):
(def routes
+ [["/kikka" ::kikka]
+ ["/bar" ::bar]])
+
+Those can be used as-is from ClojureScript:
+(require '[reitit.core :as r])
+
+(def router
+ (r/router routes))
+
+(r/match-by-name router ::kikka)
+;#Match{:template "/kikka"
+; :data {:name :user/kikka}
+; :result nil
+; :path-params nil
+; :path "/kikka"}
+
+For the backend, we can use a custom-expander to expand the routes:
+(require '[reitit.ring :as ring])
+
+(defn my-expand [registry]
+ (fn [data opts]
+ (or (if (keyword? data)
+ (some-> data
+ registry
+ (r/expand opts)
+ (assoc :name data)))
+ (r/expand data opts))))
+
+;; the handler functions
+(defn get-kikka [_] {:status 200, :body "get"})
+(defn post-kikka [_] {:status 200, :body "post"})
+(defn bar [_] {:status 200, :body "bar"})
+
+(def app
+ (ring/ring-handler
+ (ring/router
+ [["/kikka" ::kikka]
+ ["/bar" ::bar]]
+ ;; use a custom expander
+ {:expand (my-expand
+ {::kikka {:get get-kikka
+ :post post-kikka}
+ ::bar bar})})))
+
+(app {:request-method :post, :uri "/kikka"})
+; {:status 200, :body "post"}
+
+
+
+