A fast data-driven routing library for Clojure/Script
Find a file
Timo Kramer e095cd2efa Support operationId in reitit-swagger
OpenAPI Specification allows the operationId to be added to the
"Operation Object" alongside e.g. summary and description. This
commit introduces the support of this element in the
reitit-swagger module and extends the tests. One test shows the
correct use of operationId where both are distinct and one
shows the failing of the swagger creation when the IDs are not
distinct.

- Spec: https://swagger.io/specification/#operation-object
- Adds the support for operationId
- Adds operationId in two places of the swagger test
- Adds a test that checks exception on duplicate IDs
- Closes #451
2020-11-25 18:38:35 +01:00
.circleci Point to cljdoc for documentation 2020-07-28 13:15:10 +03:00
.clj-kondo Add clj-kondo and fix most linting warnings 2020-03-05 13:32:48 +02:00
dev-resources test perf with different json 2018-08-25 13:28:44 +03:00
doc Link to docs for Malli coercion 2020-11-01 16:49:03 +01:00
examples 0.5.10 2020-10-22 00:10:52 +03:00
modules Support operationId in reitit-swagger 2020-11-25 18:38:35 +01:00
perf-test/clj/reitit Faster path conflict resolution, O(n2) -> O(n) 2020-04-27 08:38:27 +03:00
scripts Better set-version 2020-05-16 18:11:13 +03:00
test Support operationId in reitit-swagger 2020-11-25 18:38:35 +01:00
.gitignore update deps 2020-09-26 12:11:14 +03:00
book.json initial rework 2018-09-02 19:23:18 +03:00
CHANGELOG.md CHANGELOG 2020-10-22 00:13:39 +03:00
CONTRIBUTING.md Fix typos 2019-05-22 19:17:10 +02:00
Justfile Add clj-kondo and fix most linting warnings 2020-03-05 13:32:48 +02:00
LICENSE Initial commit 2017-08-07 14:15:45 +03:00
lint.sh Add clj-kondo and fix most linting warnings 2020-03-05 13:32:48 +02:00
package-lock.json Update JS testing dependencies 2019-06-08 14:00:20 +03:00
package.json Update JS testing dependencies 2019-06-08 14:00:20 +03:00
project.clj 0.5.10 2020-10-22 00:10:52 +03:00
README.md 0.5.10 2020-10-22 00:10:52 +03:00

reitit Build Status cljdoc badge Slack

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

Presentations:

Full Documentation

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

Main Modules

  • reitit - all bundled
  • reitit-core - the routing core
  • reitit-ring - a ring router
  • reitit-middleware - common middleware
  • reitit-spec clojure.spec coercion
  • reitit-malli malli coercion
  • reitit-schema Schema coercion
  • reitit-swagger Swagger2 apidocs
  • reitit-swagger-ui Integrated Swagger UI
  • reitit-frontend Tools for frontend routing
  • reitit-http http-routing with Interceptors
  • reitit-interceptors - common interceptors
  • reitit-sieppari support for Sieppari
  • reitit-dev - development utilities

Extra modules

Latest version

All main modules bundled:

[metosin/reitit "0.5.10"]

Optionally, the parts can be required separately.

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

External resources

More info

Check out the full documentation!

Join #reitit channel in Clojurians slack.

Roadmap is mostly written in issues.

Special thanks

License

Copyright © 2017-2020 Metosin Oy

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