A fast data-driven routing library for Clojure/Script
Find a file
2017-12-29 12:05:23 +02:00
.circleci coveralls doesn't still work 2017-12-28 10:50:30 +02:00
dev-resources Middleware & Interceptor perf tests 2017-12-17 21:24:21 +02:00
doc dafaq 2017-12-29 12:05:12 +02:00
examples Update docs 2017-12-09 23:21:03 +02:00
modules Docs for Ring spec validation 2017-12-29 11:56:01 +02:00
perf-test/clj/reitit Middleware & Interceptor perf tests 2017-12-17 21:24:21 +02:00
scripts initial commit 2017-11-24 19:09:45 +02:00
test Docs for Ring spec validation 2017-12-29 11:56:01 +02:00
.gitignore Add karma packages 2017-10-25 17:32:12 +03:00
.travis.yml Coveralls-script doesn't work? 2017-12-28 10:07:06 +02:00
book.json Explicitly use the highlight plugin for gitbook 2017-09-14 17:39:26 +03:00
CHANGELOG.md Initial commit 2017-08-07 14:15:45 +03:00
CONTRIBUTING.md Initial commit 2017-08-07 14:15:45 +03:00
LICENSE Initial commit 2017-08-07 14:15:45 +03:00
package-lock.json Add karma packages 2017-10-25 17:32:12 +03:00
package.json Add karma packages 2017-10-25 17:32:12 +03:00
project.clj Update expound 2017-12-26 17:43:51 +02:00
README.md Polish readme 2017-12-28 11:02:39 +02:00

reitit Build Status Clojars Project

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

There are also Ring-router with data-driven middleware as a separate module.

See the full documentation for details.

Latest version

All bundled:

[metosin/reitit "0.1.0-SNAPSHOT"]

Optionally, the parts can be required separately:

[metosin/reitit-core "0.1.0-SNAPSHOT"] ; just the router
[metosin/reitit-ring "0.1.0-SNAPSHOT"] ; ring-router
[metosin/reitit-spec "0.1.0-SNAPSHOT"] ; spec coercion
[metosin/reitit-schema "0.1.0-SNAPSHOT"] ; schema coercion

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
;        :params {}
;        :path "/api/ping"}

(r/match-by-name router ::order {:id 2})
; #Match{:template "/api/orders/:id",
;        :data {:name ::order},
;        :result nil,
;        :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-middleware :as mw])

(def app
  (ring/ring-handler
    (ring/router
      ["/api"
       ["/math" {:get {:coercion reitit.coercion.spec/coercion
                       :parameters {:query {:x int?, :y int?}}
                       :responses {200 {:schema {:total pos-int?}}}
                       :handler (fn [{{{:keys [x y]} :query} :parameters}]
                                  {:status 200
                                   :body {:total (+ x y)}})}}]]
      {:data {:middleware [mw/coerce-exceptions-middleware
                           mw/coerce-request-middleware
                           mw/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 info

Check out the full documentation!

Roadmap is mostly written in issues.

There is also a #reitit channel in Clojurians slack.

Special thanks

To all Clojure(Script) routing libs out there, expecially to Ataraxy, Bide, Bidi, Compojure and Pedestal.

Also to Compojure-api, Kekkonen, Ring-swagger and Yada and for ideas, coercion & stuff.

And, of course, to: Schema and clojure.spec.

Development instructions

The documentation is built with gitbook. To preview your changes locally:

npm install -g gitbook-cli
gitbook install
gitbook serve

To bump up version:

# new version
./scripts/set-version "1.0.0"
./scripts/lein-modules install

# works
lein test

# deploy to clojars
./scripts/lein-modules do clean, deploy clojars

License

Copyright © 2017 Metosin Oy

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