Back to rankings

metosin/reitit

Clojurecljdoc.org/d/metosin/reitit/

A fast data-driven routing library for Clojure/Script

clojureclojurescriptroutingdata-drivenringswaggerinterceptorsmiddlewarepedestalfrontendmetosin-active
Star Growth
Stars
1.6k
Forks
263
Weekly Growth
Issues
72
5001k1.5k
Sep 2017Aug 2020Aug 2023Jul 2026
README

reitit

Build Status cljdoc badge Clojars Project Slack

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

Presentations:

Status: stable

Hi! We are Metosin, a consulting company. These libraries have evolved out of the work we do for our clients. We maintain & develop this project, for you, for free. Issues and pull requests welcome! However, if you want more help using the libraries, or want us to build something as cool for you, consider our commercial support.

Full Documentation

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

Main Modules

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

... * This is not a typo; the new reitit-openapi was released under the new, verified fi.metosin group. Existing modules will continue to be released under metosin for compatibility purposes.

Extra modules

Latest version

All main modules bundled:

[metosin/reitit "0.10.1"]

Optionally, the parts can be required separately.

Reitit requires Clojure 1.11 and Java 11.

Reitit is tested with the LTS releases Java 11, 17, 21 and 25

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 '[muuntaja.core :as m])
(require '[reitit.ring :as ring])
(require '[reitit.coercion.spec])
(require '[reitit.ring.coercion :as rrc])
(require '[reitit.ring.middleware.exception :as exception])
(require '[reitit.ring.middleware.muuntaja :as muuntaja])
(require '[reitit.ring.middleware.parameters :as parameters])

(def app
  (ring/ring-handler
    (ring/router
      ["/api"
       ["/math" {:get {:parameters {:query {:x int?, :y int?}}
                       :responses  {200 {:body {:total int?}}}
                       :handler    (fn [{{{:keys [x y]} :query} :parameters}]
                                     {:status 200
                                      :body   {:total (+ x y)}})}}]]
      ;; router data affecting all routes
      {:data {:coercion   reitit.coercion.spec/coercion
              :muuntaja   m/instance
              :middleware [parameters/parameters-middleware ; decoding query & form params
                           muuntaja/format-middleware       ; content negotiation
                           exception/exception-middleware   ; converting exceptions to HTTP responses
                           rrc/coerce-request-middleware
                           rrc/coerce-response-middleware]}})))

Valid request:

(-> (app {:request-method :get
          :uri "/api/math"
          :query-params {:x "1", :y "2"}})
    (update :body slurp))
; {:status 200
;  :body "{\"total\":3}"
;  :headers {"Content-Type" "application/json; charset=utf-8"}}

Invalid request:

(-> (app {:request-method :get
          :uri "/api/math"
          :query-params {:x "1", :y "a"}})
    (update :body jsonista.core/read-value))
; {:status 400
;  :headers {"Content-Type" "application/json; charset=utf-8"}
;  :body {"spec" "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$8974/x :spec$8974/y]), :type :map, :leaf? false})"
;         "value" {"x" "1"
;                  "y" "a"}
;         "problems" [{"via" ["spec$8974/y"]
;                      "path" ["y"]
;                      "pred" "clojure.core/int?"
;                      "in" ["y"]
;                      "val" "a"}]
;         "type" "reitit.coercion/request-coercion"
;         "coercion" "spec"
;         "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-2023 Metosin Oy

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

Related repositories
penpot/penpot

Penpot: The open-source design platform for Product teams that need scalable collaboration.

ClojureMozilla Public License 2.0ux-designux-experience
penpot.app
57.1k3.8k
metabase/metabase

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

ClojureOtheranalyticsbusinessintelligence
metabase.com
48.3k6.7k
logseq/logseq

A privacy-first, open-source platform for knowledge management and collaboration. Download link: http://github.com/logseq/logseq/releases. roadmap: https://logseq.io/p/NX4mc_ggEV

ClojureGNU Affero General Public License v3.0knowledge-basegraph
logseq.com
44k2.7k
deeplearning4j/deeplearning4j

Suite of tools for deploying and training deep learning models using the JVM. Highlights include model import for keras, tensorflow, and onnx/pytorch, a modular and tiny c++ library for running math code and a java based math library on top of the core c++ library. Also includes samediff: a pytorch/tensorflow like library for running deep learn...

JavaMavenApache License 2.0javagpu
deeplearning4j.konduit.ai
14.2k3.8k
LightTable/LightTable

The Light Table IDE ⛺

ClojureMIT Licenseclojurescriptide
lighttable.com
11.7k911
kanaka/mal

mal - Make a Lisp

AssemblyOthermaldocker
10.7k2.7k
lk-geimfari/awesomo

Cool open source projects. Choose your project and get involved in Open Source development now.

GoGo ModulesCreative Commons Zero v1.0 Universalawesomeocaml
9.9k690
defold/defold

Defold is a completely free to use game engine for development of desktop, mobile and web games.

C++Otherdefoldgame-engine
defold.com
6.2k440
tonsky/datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS

ClojureEclipse Public License 1.0clojuredatabase
5.8k317
reagent-project/reagent

A minimalistic ClojureScript interface to React.js

ClojureMIT Licensereagentclojurescript
reagent-project.github.io
4.9k412
izhangzhihao/intellij-rainbow-brackets

🌈Rainbow Brackets for IntelliJ based IDEs/Android Studio/HUAWEI DevEco Studio/Fleet

KotlinOtherintellij-pluginrainbow
plugins.jetbrains.com/plugin/10080-rainbow-brackets
4.7k224
babashka/babashka

Native, fast starting Clojure interpreter for scripting

ClojureEclipse Public License 1.0clojureshell-scripting
babashka.org
4.6k273