Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A fast data-driven routing library for Clojure/Script

License

NotificationsYou must be signed in to change notification settings

metosin/reitit

Repository files navigation

Build Statuscljdoc badgeClojars ProjectSlack

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

Presentations:

Status:stable

Hi! We areMetosin, 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 ourcommercial support.

There is#reitit inClojurians Slack for discussion & help.

Main Modules

  • metosin/reitit - all bundled
  • metosin/reitit-core - the routing core
  • metosin/reitit-ring - aring router
  • metosin/reitit-middleware -common middleware
  • metosin/reitit-specclojure.spec coercion
  • metosin/reitit-mallimalli coercion
  • metosin/reitit-schemaSchema coercion
  • fi.metosin/reitit-openapiOpenAPI apidocs *
  • metosin/reitit-swaggerSwagger2 apidocs
  • metosin/reitit-swagger-ui IntegratedSwagger UI
  • metosin/reitit-frontend Tools for frontend routing
  • metosin/reitit-http http-routing with Interceptors
  • metosin/reitit-interceptors -common interceptors
  • metosin/reitit-sieppari support forSieppari
  • metosin/reitit-dev - development utilities

... * This is not a typo; the newreitit-openapi was released under the new, verifiedfi.metosin group. Existingmodules will continue to be released undermetosin for compatibility purposes.

Extra modules

Latest version

All main modules bundled:

[metosin/reitit"0.9.2"]

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 and 21.

Quick start

(require '[reitit.core:as r])(defrouter  (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 {:id2}); #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 usingdata-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])(defapp  (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}]                                     {:status200: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 inhttps://github.com/metosin/reitit/tree/master/examples

External resources

More info

Check out the full documentation!

Join#reitit channel inClojurians slack.

Roadmap is mostly written inissues.

Special thanks

License

Copyright © 2017-2023Metosin Oy

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


[8]ページ先頭

©2009-2025 Movatter.jp