mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
8.9 KiB
8.9 KiB
0.2.0 (2018-09-03)
Sample apps demonstraing the current status of reitit:
reitit-ringwith coercion, swagger and default middleware: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.cljreitit-frontend, the easy way: https://github.com/metosin/reitit/blob/master/examples/frontend/src/frontend/core.cljsreitit-frontentwith Keechma-style controllers: https://github.com/metosin/reitit/blob/master/examples/frontend-controllers/src/frontend/core.cljs
reitit-core
- BREAKING: the router option key to extract body format has been renamed:
:extract-request-format=>:reitit.coercion/extract-request-format- should only concern you if you are not using Muuntaja.
- the
r/routesreturns just the path + data tuples as documented, not the compiled route results. To get the compiled results, user/compiled-routesinstead. - new faster and more correct encoders and decoders for query & path params.
- all path-parameters are now decoded correctly with
reitit.impl/url-decode, thanks to Matthew Davidson! - query-parameters are encoded with
reitit.impl/form-encode, so spaces are+instead of%20.
- all path-parameters are now decoded correctly with
- correctly read
:headerparams from request:headers, not:header-params - welcome route name conflict resolution! If router has routes with same names, router can't be created. fix 'em.
- sequential child routes are allowed, enabling this:
(-> ["/api"
(for [i (range 4)]
[(str "/" i)])]
(r/router)
(r/routes))
;[["/api/0" {}]
; ["/api/1" {}]
; ["/api/2" {}]
; ["/api/3" {}]]
- A Guide to compose routers
- Welcome Middleware and Intercetor Registries!
(require '[reitit.ring :as ring])
(require '[reitit.middleware :as middleware])
(defn wrap-bonus [handler value]
(fn [request]
(handler (update request :bonus (fnil + 0) value))))
(def app
(ring/ring-handler
(ring/router
["/api" {:middleware [[:bonus 20]]}
["/bonus" {:middleware [:bonus10]
:get (fn [{:keys [bonus]}]
{:status 200, :body {:bonus bonus}})}]]
{::middleware/registry {:bonus wrap-bonus
:bonus10 [:bonus 10]}})))
(app {:request-method :get, :uri "/api/bonus"})
; {:status 200, :body {:bonus 30}}
reitit-swagger
- In case of just one swagger api per router, the swagger api doesn't have to identified, so this works now:
(require '[reitit.ring :as ring])
(require '[reitit.swagger :as swagger])
(require '[reitit.swagger-ui :as swagger-ui])
(ring/ring-handler
(ring/router
[["/ping"
{:get (fn [_] {:status 200, :body "pong"})}]
["/swagger.json"
{:get {:no-doc true
:handler (swagger/create-swagger-handler)}}]])
(swagger-ui/create-swagger-ui-handler {:path "/"}))
reitit-middleware
- A new module with common data-driven middleware: exception handling, content negotiation & multipart requests. See the docs.
reitit-swagger-ui
- BREAKING: pass swagger-ui
:configas-is (instead of mixed-casing keys) to swagger-ui, fixes #109:- see docs for available parameters.
(swagger-ui/create-swagger-ui-handler
{:path "/"
:url "/api/swagger.json"
:config {:jsonEditor true
:validatorUrl nil}})
reitit-frontend
- new module for frontend-routing. See docs for details.
0.1.3 (2018-6-25)
reitit-core
reitit.coercion/coerce!coerced all parameters found in match, e.g. injecting in:query-parametersintoMatchwith coerce those too if:querycoercion is defined.- if response coercion is not defined for a response status, response is still returned
spec-tools.data-spec/maybecan be used in spec-coercion.
(def router
(reitit.core/router
["/spec" {:coercion reitit.coercion.spec/coercion}
["/:number/:keyword" {:parameters {:path {:number int?
:keyword keyword?}
:query (ds/maybe {:int int?})}}]]
{:compile reitit.coercion/compile-request-coercers}))
(-> (reitit.core/match-by-path router "/spec/10/kikka")
(assoc :query-params {:int "10"})
(reitit.coercion/coerce!))
; {:path {:number 10, :keyword :kikka}
; :query {:int 10}}
reitit.core/match->pathto create full paths from match, including the query parameters:
(require '[reitit.core :as r])
(-> (r/router ["/:a/:b" ::route])
(r/match-by-name! ::route {:a "olipa", :b "kerran"})
(r/match->path))
; "/olipa/kerran"
(-> (r/router ["/:a/:b" ::route])
(r/match-by-name! ::route {:a "olipa", :b "kerran"})
(r/match->path {:iso "pöriläinen"}))
; "/olipa/kerran?iso=p%C3%B6ril%C3%A4inen"
reitit-spec
[metosin/spec-tools "0.7.1"]with swagger generation enhancements, see the CHANGELOG- if response coercion is not defined for a response status, no
:schemais not emitted. - updated dependencies:
[metosin/spec-tools "0.7.1"] is available but we use "0.7.0"
reitit-schema
- if response coercion is not defined for a response status, no
:schemais not emitted.
0.1.2 (2018-6-6)
reitit-core
- Better handling of
nilin route syntax:- explicit
nilafter path string is always handled asnilroute nilas path string causes the whole route to benilnilas child route is stripped away
- explicit
(testing "nil routes are stripped"
(is (= [] (r/routes (r/router nil))))
(is (= [] (r/routes (r/router [nil ["/ping"]]))))
(is (= [] (r/routes (r/router [nil [nil] [[nil nil nil]]]))))
(is (= [] (r/routes (r/router ["/ping" [nil "/pong"]])))))
reitit-ring
- Use HTTP redirect (302) with index-files in
reitit.ring/create-resource-handler. reitit.ring/create-default-handlernow conforms to RING Spec, Fixes #83
reitit-schema
- updated dependencies:
[metosin/schema-tools "0.10.3"] is available but we use "0.10.2"
reitit-swagger
- Fix Swagger-paths, by Kirill Chernyshov.
reitit-swagger-ui
-
Use HTTP redirect (302) with index-files in
reitit.swagger-ui/create-swagger-ui-handler. -
updated dependencies:
[metosin/jsonista "0.2.1"] is available but we use "0.2.0"
0.1.1 (2018-5-20)
reitit-core
linear-routernow works with unnamed catch-all parameters, e.g."/files/*"match-by-pathencodes parameters into strings using (internal)reitit.impl/IntoStringprotocol. Handles all of: strings, numbers, keywords, booleans, objects. Fixes #75.
(require '[reitit.core :as r])
(r/match-by-name
(r/router
["/coffee/:type" ::coffee])
::coffee
{:type :luwak})
;#Match{:template "/coffee/:type",
; :data {:name :user/coffee},
; :result nil,
; :path-params {:type "luwak"},
; :path "/coffee/luwak"}
reitit-ring
-
reitit.ring/default-handlernow works correctly with async ring -
new helper
reitit.ring/routerto compose routes outside of a router. -
reitit.ring/create-resource-handlerfunction to serve static routes. See docs. -
new dependencies:
[ring/ring-core "1.6.3"]
reitit-swagger
- New module to produce swagger-docs from routing tree, including
Coerciondefinitions. Works with both middleware & interceptors and Schema & Spec. See docs and example project.
reitit-swagger-ui
New module to server pre-integrated Swagger-ui. See docs.
- new dependencies:
[metosin/jsonista "0.2.0"]
[metosin/ring-swagger-ui "2.2.10"]
dependencies
[metosin/spec-tools "0.7.0"] is available but we use "0.6.1"
[metosin/schema-tools "0.10.2"] is available but we use "0.10.1"
0.1.0 (2018-2-19)
- First release