reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
2020-07-08T18:55:26.214400Z

Does anyone know an example that shows how authentication & authorization is done with reitit?

byrongibby 2020-07-09T09:17:30.218200Z

Hey. I am busy figuring this out myself at the moment. I decided to go with https://github.com/funcool/buddy-auth. Let me know if you have any questions I can help you answer.

byrongibby 2020-07-09T10:30:12.218500Z

I created an example building on a previous one. Not sure if this is the recommended way of doing things, but it works for me. Let me know if it is useful.

valtteri 2020-07-11T10:41:26.221900Z

I whipped up a PR with annotated example how to use Buddy to implement simple authentication and authorization with reitit. https://github.com/metosin/reitit/pull/419 Feedback is very welcome. 🙂

2020-07-08T20:26:01.217900Z

I have this route running on localhost and am trying to post a file to it using clj-http.

["/upload" {:post {:summary    "upload an artifact"
                        :parameters {:multipart {:file multipart/temp-file-part}}
                        :handler    (fn [request]
                                      (ok (select-keys
                                            request
                                            [:form-params
                                             :query-params
                                             :path-params
                                             :parameters])))}}]
I've tried a wide variety of permutations of the client invocation. For example, this contains some of the variants:
(let [mp {:name "foo.json" :content (io/file "foo.json")}]
    (->> {:method           :post
          :throw-exceptions false
          :url              "<http://localhost:3000/upload>"
          :params           {:file mp}
          :form-params      {:file mp}
          :multipart-params {:file mp}
          :multipart        [mp]
          }
         client/request
         :body
         ch/parse-string))
I keep getting this spec error:
{"spec" "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$47151/file]), :type :map, :leaf? false})",
 "problems" [{"path" [],
              "pred" "(clojure.core/fn [%] (clojure.core/contains? % :file))",
              "val" {},
              "via" [],
              "in" []}],
 "type" "reitit.coercion/request-coercion",
 "coercion" "spec",
 "value" {},
 "in" ["request" "multipart-params"]}
Somehow I need to modify my client request to make the service happy. Any ideas as to what the right client request is? Here is working curl version:
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' {"type":"formData"} '<http://localhost:3000/upload>'

2020-07-08T20:34:43.218Z

I think I got it:

(client/request
    {:url       "<http://localhost:3000/upload>"
     :method    :post
     :multipart [{:name "file" :content (io/file "foo.json")}]})
I swear I tried that before.