A fast data-driven routing library for Clojure/Script
Find a file
Juho Teperi cbff7d10bf Fix HTML5 history in IE11 (and hopefully others)
closest method is not available in IE, but we only need to find ancestor
by tag name which is easy and relatively fast anyway.
2019-02-08 14:44:28 +02:00
.circleci Add step to verify cljdoc.edn as part of CI 2018-10-22 20:46:48 +02:00
dev-resources test perf with different json 2018-08-25 13:28:44 +03:00
doc Tune wording 2019-02-08 10:23:31 +02:00
examples Simplify contentEditable check for frontend routing 2019-02-08 13:57:03 +02:00
modules Fix HTML5 history in IE11 (and hopefully others) 2019-02-08 14:44:28 +02:00
perf-test/clj/reitit uncomment 2019-01-17 11:20:49 +02:00
scripts Reitit-pedestal 2018-12-26 15:43:26 +02:00
test Replace controller :params with :identity and :parameters 2019-02-08 10:22:29 +02:00
.gitignore Create example 2018-07-12 12:46:41 +03:00
book.json initial rework 2018-09-02 19:23:18 +03:00
CHANGELOG.md Replace controller :params with :identity and :parameters 2019-02-08 10:22:29 +02:00
CONTRIBUTING.md Correct testing instructions for contributors 2018-10-31 09:36:45 +02:00
LICENSE Initial commit 2017-08-07 14:15:45 +03:00
package-lock.json Run CLJS tests in Circle 2018-03-13 14:47:04 +02:00
package.json Run CLJS tests in Circle 2018-03-13 14:47:04 +02:00
project.clj 0.2.13 2019-01-26 16:20:19 +02:00
README.md 0.2.13 2019-01-26 16:20:19 +02:00

reitit Build Status cljdoc badge

A fast data-driven router for Clojure(Script).

Posts:

Full Documentation

There is #reitit in Clojurians Slack for discussion & help.

Main Modules

Extra modules

Latest version

All main modules bundled:

[metosin/reitit "0.2.13"]

Optionally, the parts can be required separately:

[metosin/reitit-core "0.2.13"]

;; coercion
[metosin/reitit-spec "0.2.13"]
[metosin/reitit-schema "0.2.13"]

;; ring helpers
[metosin/reitit-ring "0.2.13"]
[metosin/reitit-middleware "0.2.13"]

;; swagger-support for ring & http
[metosin/reitit-swagger "0.2.13"]
[metosin/reitit-swagger-ui "0.2.13"]

;; frontend helpers
[metosin/reitit-frontend "0.2.13"]

;; http with interceptors
[metosin/reitit-http "0.2.13"]
[metosin/reitit-interceptors "0.2.13"]
[metosin/reitit-sieppari "0.2.13"]
;; pedestal
[metosin/reitit-pedestal "0.2.13"]

Quick start

(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"}

Ring example

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]}}

More examples

All examples are in https://github.com/metosin/reitit/tree/master/examples

More info

Check out the full documentation!

Join #reitit channel in Clojurians slack.

Roadmap is mostly written in issues.

Special thanks

License

Copyright © 2017-2019 Metosin Oy

Distributed under the Eclipse Public License, the same as Clojure.