A fast data-driven router for Clojure(Script).
- Simple data-driven route syntax
- Route conflict resolution
- First-class route data
- Bi-directional routing
- Pluggable coercion (schema & clojure.spec)
- Helpers for ring, http & the browser
- Extendable
- Modular
- Fast
Posts:
See the full documentation for details.
There is #reitit in Clojurians Slack for discussion & help.
reitit
- all bundledreitit-core
- the routing corereitit-ring
- a ring routerreitit-middleware
- common middleware forreitit-ring
reitit-spec
clojure.spec coercionreitit-schema
Schema coercionreitit-swagger
Swagger2 apidocsreitit-swagger-ui
Integrated Swagger UIreitit-frontend
Tools for frontend routingreitit-http
http-routing with Pedestal-style Interceptorsreitit-interceptors
- common interceptors forreitit-http
reitit-sieppari
support for Sieppari Interceptors
All bundled:
[metosin/reitit "0.2.3"]
Optionally, the parts can be required separately:
[metosin/reitit-core "0.2.3"]
;; coercion
[metosin/reitit-spec "0.2.3"]
[metosin/reitit-schema "0.2.3"]
;; ring helpers
[metosin/reitit-ring "0.2.3"]
[metosin/reitit-middleware "0.2.3"]
;; swagger-support for ring & http
[metosin/reitit-swagger "0.2.3"]
[metosin/reitit-swagger-ui "0.2.3"]
;; frontend helpers
[metosin/reitit-frontend "0.2.3"]
;; http with interceptors
[metosin/reitit-http "0.2.3"]
[metosin/reitit-interceptors "0.2.3"]
[metosin/reitit-sieppari "0.2.3"]
(require '[reitit.core :as r])
(def router
(r/router
[["/api/ping" ::ping]
["/api/orders/:id" ::order]]))
(r/match-by-path router "/api/ping")
; #Match{:template "/api/ping"
; :data {:name ::ping}
; :result nil
; :path-params {}
; :path "/api/ping"}
(r/match-by-name router ::order {:id 2})
; #Match{:template "/api/orders/:id",
; :data {:name ::order},
; :result nil,
; :path-params {:id 2},
; :path "/api/orders/2"}
A Ring routing app with input & output coercion using data-specs.
(require '[reitit.ring :as ring])
(require '[reitit.coercion.spec])
(require '[reitit.ring.coercion :as rrc])
(def app
(ring/ring-handler
(ring/router
["/api"
["/math" {:get {:parameters {:query {:x int?, :y int?}}
:responses {200 {:body {:total pos-int?}}}
:handler (fn [{{{:keys [x y]} :query} :parameters}]
{:status 200
:body {:total (+ x y)}})}}]]
;; router data effecting all routes
{:data {:coercion reitit.coercion.spec/coercion
:middleware [rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware]}})))
Valid request:
(app {:request-method :get
:uri "/api/math"
:query-params {:x "1", :y "2"}})
; {:status 200
; :body {:total 3}}
Invalid request:
(app {:request-method :get
:uri "/api/math"
:query-params {:x "1", :y "a"}})
;{:status 400,
; :body {:type :reitit.coercion/request-coercion,
; :coercion :spec,
; :spec "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:$spec20745/x :$spec20745/y]), :type :map, :keys #{:y :x}, :keys/req #{:y :x}})",
; :problems [{:path [:y],
; :pred "clojure.core/int?",
; :val "a",
; :via [:$spec20745/y],
; :in [:y]}],
; :value {:x "1", :y "a"},
; :in [:request :query-params]}}
reitit-ring
with coercion, swagger and default middlewarereitit-frontend
, the easy wayreitit-frontent
with Keechma-style controllersreitit-http
with Pedestalreitit-http
with Sieppari
All examples are in https://github.com/metosin/reitit/tree/master/examples
Check out the full documentation!
Join #reitit channel in Clojurians slack.
Roadmap is mostly written in issues.
- Existing Clojure(Script) routing libs, expecially to Ataraxy, Bide, Bidi, Compojure and Pedestal.
- Compojure-api, Kekkonen, Ring-swagger and Yada and for ideas, coercion & stuff.
- Schema and clojure.spec for the validation part.
Copyright © 2017-2018 Metosin Oy
Distributed under the Eclipse Public License, the same as Clojure.