This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-03
Channels
- # aleph (3)
- # beginners (139)
- # boot (3)
- # cider (12)
- # cljs-dev (18)
- # clojure (100)
- # clojure-dev (21)
- # clojure-dusseldorf (5)
- # clojure-germany (1)
- # clojure-italy (35)
- # clojure-nl (26)
- # clojure-spec (4)
- # clojure-uk (60)
- # clojurescript (11)
- # clojutre (4)
- # cursive (21)
- # data-science (21)
- # datomic (47)
- # editors (3)
- # emacs (2)
- # events (4)
- # figwheel (2)
- # fulcro (28)
- # jobs (27)
- # jobs-discuss (21)
- # lein-figwheel (3)
- # midje (2)
- # off-topic (20)
- # om-next (4)
- # onyx (10)
- # overtone (1)
- # pedestal (2)
- # portkey (14)
- # re-frame (71)
- # reagent (44)
- # reitit (11)
- # remote-jobs (1)
- # ring-swagger (4)
- # shadow-cljs (64)
- # spacemacs (11)
- # testing (2)
- # tools-deps (8)
- # vim (8)
@ikitommi yeah I ended up going with middleware outside reitit, but I agree it would be nice to have first class support for that at some point. Would something like the following make sense for the syntax?
["/restricted/media"
{:post
{:summary "add a media attachment"
:parameters {:multipart {:file TempFileUpload}}
:handler (fn [{{ {{:keys [tempfile filename content-type]} :file} :multipart} :parameters}]
(attachments/upload-media! {:user-id (:user-id identity)} file))}}]
the TempFileUpload
would be the schema/spec definition for the multipart param same as in compojure-api, and then the :file
param would contain the standard Ring multipart map with the :tempfile
, :filename
, and :content-type
keysWhen I use data-spec
to specify parameters, if I say {:id int?}
it is somehow converted into something that conforms. Is there a list of predicate symbols that get converted to their spec-tools
coercing form automagically?
@roklenarcic you should use coercion middleware to compile coercers with ring, should be described in the docs. the compile-request-coercers
doesn't understand the endpoints (`:get`, :post
etc).
the data-spec
... in reitit.coercion.spec
, there is a IntoSpec
protocol, which converts maps into data-specs. With data-specs, all map keys and values are wrapped into spec-tools.core.Spec
, which does automatic type-resolution for predicates. Most core predicates are supported oob, and it's extendable. Here's the list: https://github.com/metosin/spec-tools/blob/master/src/spec_tools/parse.cljc
Oh I have coercion middleware, I just wasn't aware that it did compilation of coercions without explicit :compile
in the map.
(defn create-router [router-data]
(rr/router router-data
{:data {:coercion reitit.coercion.spec/coercion
:middleware [[mm/wrap-format muuntaja]
rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware]}
}))
re: muuntaja, if I add the middleware to a specific path in my route data, then the middleware gets added at the end of middleware stack, which doesn't work well for muuntaja. Is there some way to add middleware at the start of middleware stack?
@roklenarcic would :middleware ^:prepend [wrap-format]
work? Reitit uses meta-merge under the hoods (https://github.com/weavejester/meta-merge/blob/master/README.md#metadata)
probably