A fast data-driven routing library for Clojure/Script
Find a file
Martin Klepsch fc7ae2252f
fix various links in documentation
These probably work in Gitbook to some extent but they don't work on
GitHub. In most places of the documentation files are referenced
via their source files (`.md`) and I assume Gitbook deals fine with that

For cljdoc the correct links are required to properly fix links that are
broken when rendering the document on different URLs.
2018-05-20 12:04:49 +02:00
.circleci Run CLJS tests in Circle 2018-03-13 14:47:04 +02:00
dev-resources Support :index-files in create-resource-handler 2018-04-29 16:51:53 +03:00
doc fix various links in documentation 2018-05-20 12:04:49 +02:00
examples Update docs 2018-05-14 08:22:06 +03:00
modules no-op-transformer 2018-05-14 08:31:49 +03:00
perf-test/clj/reitit use ring for serving resources. 2018-04-25 08:32:01 +03:00
scripts welcome swagger-ui! 2018-05-14 08:21:47 +03:00
test cljdoc 2018-05-18 18:42:10 +03:00
.gitignore Add karma packages 2017-10-25 17:32:12 +03:00
book.json Explicitly use the highlight plugin for gitbook 2017-09-14 17:39:26 +03:00
CHANGELOG.md spec-tools 0.7.0 2018-05-14 16:50:20 +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 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 spec-tools 0.7.0 2018-05-14 16:50:20 +03:00
README.md Update docs 2018-05-14 08:22:06 +03:00

reitit Build Status

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

The following higher-level routers are also available as separate modules:

Posts:

See the full documentation for details.

Latest version

All bundled:

[metosin/reitit "0.1.1-SNAPSHOT"]

Optionally, the parts can be required separately:

[metosin/reitit-core "0.1.1-SNAPSHOT"] ; routing core
[metosin/reitit-ring "0.1.1-SNAPSHOT"] ; ring-router
[metosin/reitit-spec "0.1.1-SNAPSHOT"] ; spec coercion
[metosin/reitit-schema "0.1.1-SNAPSHOT"] ; schema coercion
[metosin/reitit-swagger "0.1.1-SNAPSHOT"] ; swagger
[metosin/reitit-swagger-ui "0.1.1-SNAPSHOT"] ; swagger-ui

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 info

Check out the full documentation!

Join #reitit channel in Clojurians slack.

Roadmap is mostly written in issues.

Special thanks

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-2018 Metosin Oy

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