This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-17
Channels
- # bangalore-clj (1)
- # beginners (70)
- # boot (1)
- # cider (39)
- # cljs-dev (69)
- # clojure (56)
- # clojure-dev (1)
- # clojure-norway (1)
- # clojure-russia (4)
- # clojure-spec (1)
- # clojure-uk (10)
- # clojurescript (34)
- # clr (3)
- # community-development (3)
- # component (1)
- # datascript (1)
- # datomic (7)
- # emacs (1)
- # figwheel (3)
- # fulcro (5)
- # graphql (2)
- # hoplon (75)
- # jobs (4)
- # jobs-discuss (1)
- # luminus (15)
- # planck (3)
- # portkey (55)
- # re-frame (2)
- # reagent (2)
- # reitit (3)
- # ring (13)
- # ring-swagger (1)
- # shadow-cljs (72)
- # spacemacs (4)
- # tools-deps (2)
- # unrepl (7)
- # vim (2)
Initial swagger-support landed on master, as a separate module reitit/swagger
. schema is still WIP, spec works with both clj & cljs. Body-formatting middleware/interceptor is this only difference between JVM & node -targets.
If Muuntaja would target node too, the examples would look identical. Maybe it should…
(require '[reitit.ring :as ring])
(require '[reitit.swagger :as swagger])
(require '[reitit.ring.coercion :as rrc])
(require '[reitit.coercion.spec :as spec])
(require '[reitit.coercion.schema :as schema])
(require '[schema.core :refer [Int]])
(require '[muuntaja.middleware])
(ring/ring-handler
(ring/router
["/api"
{:swagger {:id ::math}}
["/swagger.json"
{:get {:no-doc true
:swagger {:info {:title "my-api"}}
:handler swagger/swagger-spec-handler}}]
["/spec" {:coercion spec/coercion}
["/plus"
{:get {:summary "plus"
:parameters {:query {:x int?, :y int?}}
:responses {200 {:body {:total int?}}}
:handler (fn [{{{:keys [x y]} :query} :parameters}]
{:status 200, :body {:total (+ x y)}})}}]]
["/schema" {:coercion schema/coercion}
["/plus"
{:get {:summary "plus"
:parameters {:query {:x Int, :y Int}}
:responses {200 {:body {:total Int}}}
:handler (fn [{{{:keys [x y]} :query} :parameters}]
{:status 200, :body {:total (+ x y)}})}}]]]
{:data {:middleware [muuntaja.middleware/wrap-format
swagger/swagger-feature
rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware]}}))