Giter Club home page Giter Club logo

reitit's Introduction

reitit Build Status cljdoc badge Slack

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

Presentations:

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.12"]

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 affecting 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-2021 Metosin Oy

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

reitit's People

Contributors

ikitommi avatar deraen avatar valerauko avatar miikka avatar koura avatar vharmain avatar caioaao avatar dawranliou avatar dancek avatar johannesloetzsch avatar heyarne avatar olimsaidov avatar fraxu avatar alexanderjamesking avatar zelark avatar piotr-yuxuan avatar wandersoncferreira avatar jahson avatar prestancedesign avatar martinklepsch avatar delaguardo avatar viesti avatar kwrooijen avatar karimarttila avatar kanwei avatar dharrigan avatar thenonameguy avatar smahood avatar aisamu avatar mchughs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.