reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
Steven Deobald 2020-10-09T13:21:53.101600Z

it's extremely likely this isn't the channel to ask this question (happy to hear suggestions, though) but i'll try anyway: i'm moving some very "crud-ful" views and forms out of a rails app and into this clojure project. rails tends to be pretty smart about very dumb things and these user interfaces will never be fancy: they're backend-only and will only ever see a handful of users, so i'll never allow the team to turn this into a fancy javascript/clojurescript ui. for this "crud-ful" portion of the app, i'd love to dig into a toolbox of simple and boring form/handler utilities. does anyone here have any recommendations?

2020-10-09T20:22:53.106300Z

Is it possible to do nontrivial multipart form params with the new malli coercers? I tried something along these lines with spec a while ago without success but was hoping the new malli library would enable it. For example, I'm attempting to modify https://github.com/metosin/reitit/blob/master/examples/ring-malli-swagger/src/example/server.clj#L35-L42 to look something like this:

["/upload"
         {:post {:summary    "upload a file"
                 :parameters {:multipart [:map
                                          [:file reitit.ring.malli/temp-file-part]
                                          [:type string?]
                                          [:tags [:sequential string?]]
                                          [:attributes [:map
                                                        [:stars int?]
                                                        [:location string?]]]]}
                 :responses  {200 {:body [:map [:name string?] [:size int?]]}}
                 :handler    (fn [{{{:keys [file]} :multipart} :parameters}]
                               {:status 200
                                :body   {:name (:filename file)
                                         :size (:size file)}})}}]
When I try this (example post: curl -X POST "http://localhost:3000/files/upload" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@test.json;type=application/json" -F "type=json" -F "tags="red","green","blue"" -F "attributes={"stars":3, "location": "beach"}") I get a classcast exception. Is this something I can do with different coercion logic using malli or is this really just not the way multipart form params should be used?

2020-10-09T20:25:02.106500Z

FYI, tags and attributes are the pain points. Simple key-value items work fine (like the type key).